summaryrefslogtreecommitdiffstats
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-25 06:12:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-25 06:12:44 +0000
commit1f721fb67030e3864fde26f2d1790ba4cac68360 (patch)
tree3e499463b9a5a46863d28ddbb873211bc5d8cfe7 /ruby.c
parent2366b9a005eeab5370c3dd088db3384cecba3c91 (diff)
downloadruby-1f721fb67030e3864fde26f2d1790ba4cac68360.tar.gz
ruby-1f721fb67030e3864fde26f2d1790ba4cac68360.tar.xz
ruby-1f721fb67030e3864fde26f2d1790ba4cac68360.zip
* ruby.c (process_options): not set encoding of -e option from -E
option if they are not compatible. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/ruby.c b/ruby.c
index fbd255ecc..763f3b8e5 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1000,14 +1000,30 @@ process_options(VALUE arg)
enc = rb_enc_from_index(opt->ext.enc.index);
}
else {
- enc = rb_locale_encoding();
+ enc = 0;
}
if (opt->e_script) {
- rb_enc_associate(opt->e_script, enc);
+ rb_encoding *eenc = rb_locale_encoding();
+ if (!enc) {
+ enc = eenc;
+ }
+ else if (!rb_enc_asciicompat(enc)) {
+ rb_warning("%s is not ASCII compatible, ignored for -e",
+ rb_enc_name(enc));
+ }
+ else if (eenc != enc &&
+ (rb_enc_str_coderange(opt->e_script) != ENC_CODERANGE_7BIT)) {
+ rb_warning("-e conatains non ASCII string, encoding %s is not used",
+ rb_enc_name(enc));
+ }
+ rb_enc_associate(opt->e_script, eenc);
require_libraries();
tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
}
else {
+ if (!enc) {
+ enc = rb_locale_encoding();
+ }
if (opt->script[0] == '-' && !opt->script[1]) {
forbid_setid("program input from stdin");
}