зеркало из https://github.com/github/ruby.git
* 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:
Родитель
8987b97ca9
Коммит
f38cc001a7
|
@ -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
12
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);
|
||||
|
|
|
@ -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"))
|
||||
|
|
Загрузка…
Ссылка в новой задаче