From 316210b80bd0afff27be5925dbf5521982bebe93 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 29 Dec 2014 09:58:48 +0000 Subject: [PATCH] re.c: append excape sequence as-is * re.c (unescape_nonascii): append excape sequence as-is not unescaped character, to get rid of unexpected meta-character. [ruby-core:67193] [Bug #10670] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ re.c | 3 ++- test/ruby/test_m17n.rb | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5a8fc5397b..5f8de7ca65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Dec 29 18:58:46 2014 Nobuyoshi Nakada + + * re.c (unescape_nonascii): append excape sequence as-is not + unescaped character, to get rid of unexpected meta-character. + [ruby-core:67193] [Bug #10670] + Mon Dec 29 14:27:33 2014 Nobuyoshi Nakada * doc/syntax/literals.rdoc (Symbols): now Symbols created by diff --git a/re.c b/re.c index 1a0f0b182b..1f88d6053c 100644 --- a/re.c +++ b/re.c @@ -2298,9 +2298,10 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc, case 'M': /* \M-X, \M-\C-X, \M-\cX */ p = p-2; if (enc == rb_usascii_encoding()) { + const char *pbeg = p; c = read_escaped_byte(&p, end, err); if (c == (char)-1) return -1; - rb_str_buf_cat(buf, &c, 1); + rb_str_buf_cat(buf, pbeg, p-pbeg); } else { if (unescape_escaped_nonascii(&p, end, enc, buf, encp, err) != 0) diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 99450723cf..99a6b3130f 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1579,4 +1579,13 @@ class TestM17N < Test::Unit::TestCase assert_same(str, str.scrub!) assert_equal("\uFFFD\uFFFD\uFFFD", str) end + + def test_escaped_metachar + bug10670 = '[ruby-core:67193] [Bug #10670]' + + escape_plain = /\A[\x5B]*\z/.freeze + + assert_match(escape_plain, 0x5b.chr(::Encoding::UTF_8), bug10670) + assert_match(escape_plain, 0x5b.chr, bug10670) + end end