[前][次][番号順一覧][スレッド一覧]

ruby-changes:36977

From: nobu <ko1@a...>
Date: Mon, 29 Dec 2014 18:59:04 +0900 (JST)
Subject: [ruby-changes:36977] nobu:r49058 (trunk): re.c: append excape sequence as-is

nobu	2014-12-29 18:58:48 +0900 (Mon, 29 Dec 2014)

  New Revision: 49058

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49058

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_m17n.rb
Index: re.c
===================================================================
--- re.c	(revision 49057)
+++ re.c	(revision 49058)
@@ -2298,9 +2298,10 @@ unescape_nonascii(const char *p, const c https://github.com/ruby/ruby/blob/trunk/re.c#L2298
               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)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49057)
+++ ChangeLog	(revision 49058)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec 29 18:58:46 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <nobu@r...>
 
 	* doc/syntax/literals.rdoc (Symbols): now Symbols created by
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 49057)
+++ test/ruby/test_m17n.rb	(revision 49058)
@@ -1579,4 +1579,13 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L1579
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]