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

re.c: mak eregexps with binary escapes ASCII-8BIT

* re.c (unescape_nonascii): make dynamically compiled US-ASCII
  regexps ASCII-8BIT encoding if binary (hexadecimal, control,
  meta) escapes are contained, as well as literal regexps.
  [ruby-dev:48626] [Bug #10382]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-10-17 06:06:43 +00:00
parent 4f07b14190
commit a2797a454c
3 changed files with 19 additions and 2 deletions

View file

@ -1,3 +1,10 @@
Fri Oct 17 15:06:49 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* re.c (unescape_nonascii): make dynamically compiled US-ASCII
regexps ASCII-8BIT encoding if binary (hexadecimal, control,
meta) escapes are contained, as well as literal regexps.
[ruby-dev:48626] [Bug #10382]
Fri Oct 17 03:05:08 2014 Eric Wong <e@80x24.org>
* test/-ext-/bug_reporter/test_bug_reporter.rb

11
re.c
View file

@ -2284,8 +2284,15 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
case 'C': /* \C-X, \C-\M-X */
case 'M': /* \M-X, \M-\C-X, \M-\cX */
p = p-2;
if (unescape_escaped_nonascii(&p, end, enc, buf, encp, err) != 0)
return -1;
if (enc == rb_usascii_encoding()) {
c = read_escaped_byte(&p, end, err);
if (c == -1) return -1;
rb_str_buf_cat(buf, &c, 1);
}
else {
if (unescape_escaped_nonascii(&p, end, enc, buf, encp, err) != 0)
return -1;
}
break;
case 'u':

View file

@ -480,6 +480,9 @@ class TestM17N < Test::Unit::TestCase
assert_regexp_fixed_ascii8bit(eval(a(%{/\xc2\xa1/n})))
assert_regexp_fixed_ascii8bit(eval(a(%q{/\xc2\xa1/})))
s = '\xc2\xa1'
assert_regexp_fixed_ascii8bit(/#{s}/)
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|