summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--re.c12
-rw-r--r--test/ruby/test_m17n.rb2
3 files changed, 17 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 2576b21..8c8fb47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jan 6 21:14:12 2008 Tanaka Akira <akr@fsij.org>
+
+ * re.c (rb_reg_initialize_str): forbid raw non ASCII character
+ for ASCII-8BIT regexp in non ASCII-8BIT script.
+
Sun Jan 6 18:19:12 2008 Tanaka Akira <akr@fsij.org>
* include/ruby/encoding.h (rb_enc_str_buf_cat): declared.
diff --git a/re.c b/re.c
index 8fd8062..fb05e2e 100644
--- a/re.c
+++ b/re.c
@@ -2037,8 +2037,16 @@ rb_reg_initialize_str(VALUE obj, VALUE str, int options, onig_errmsg_buffer err)
{
int ret;
rb_encoding *enc = rb_enc_get(str);
- if (options & ARG_ENCODING_NONE)
- enc = rb_ascii8bit_encoding();
+ if (options & ARG_ENCODING_NONE) {
+ rb_encoding *ascii8bit = rb_ascii8bit_encoding();
+ if (enc != ascii8bit) {
+ if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
+ strcpy(err, "/.../n has a non escaped non ASCII character in non ASCII-8BIT script");
+ return -1;
+ }
+ enc = ascii8bit;
+ }
+ }
ret = rb_reg_initialize(obj, RSTRING_PTR(str), RSTRING_LEN(str), enc,
options, err);
RB_GC_GUARD(str);
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 590b22f..b15bcfd 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -320,6 +320,8 @@ class TestM17N < Test::Unit::TestCase
assert_regexp_fixed_ascii8bit(eval(a(%{/\xc2\xa1/n})))
assert_regexp_fixed_ascii8bit(eval(a(%q{/\xc2\xa1/})))
+ assert_raise(SyntaxError) { eval("/\xa1\xa1/n".force_encoding("euc-jp")) }
+
[/\xc2\xa1/n, eval(a(%{/\xc2\xa1/})), eval(a(%{/\xc2\xa1/n}))].each {|r|
assert_equal(nil, r =~ a("a"))
assert_equal(nil, r =~ e("a"))