1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* re.c (rb_reg_initialize_str): forbid raw non ASCII character

for ASCII-8BIT regexp in non ASCII-8BIT script.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-01-06 12:15:48 +00:00
parent 8987b97ca9
commit f38cc001a7
3 changed files with 17 additions and 2 deletions

View file

@ -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.

12
re.c
View file

@ -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);

View file

@ -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"))