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

ruby-changes:41092

From: nobu <ko1@a...>
Date: Thu, 17 Dec 2015 09:46:38 +0900 (JST)
Subject: [ruby-changes:41092] nobu:r53167 (trunk): re.c: names encoding

nobu	2015-12-17 09:46:07 +0900 (Thu, 17 Dec 2015)

  New Revision: 53167

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

  Log:
    re.c: names encoding
    
    * re.c (reg_names_iter): should consider encoding of regexp.
      [ruby-core:72185] [Bug #11825]

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_regexp.rb
Index: re.c
===================================================================
--- re.c	(revision 53166)
+++ re.c	(revision 53167)
@@ -757,7 +757,7 @@ reg_names_iter(const OnigUChar *name, co https://github.com/ruby/ruby/blob/trunk/re.c#L757
           int back_num, int *back_refs, OnigRegex regex, void *arg)
 {
     VALUE ary = (VALUE)arg;
-    rb_ary_push(ary, rb_str_new((const char *)name, name_end-name));
+    rb_ary_push(ary, rb_enc_str_new((const char *)name, name_end-name, regex->enc));
     return 0;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53166)
+++ ChangeLog	(revision 53167)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 17 09:46:08 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* re.c (reg_names_iter): should consider encoding of regexp.
+	  [ruby-core:72185] [Bug #11825]
+
 Thu Dec 17 03:52:10 2015  Koichi Sasada  <ko1@a...>
 
 	* vm.c (vm_make_env_each): should not compare with Qfalse and FALSE.
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 53166)
+++ test/ruby/test_regexp.rb	(revision 53167)
@@ -119,13 +119,19 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L119
     assert_equal(nil, Regexp.last_match(1))
     assert_equal(nil, Regexp.last_match(:foo))
 
+    bug11825_name = "\u{5b9d 77f3}"
+    bug11825_str = "\u{30eb 30d3 30fc}"
+    bug11825_re = /(?<#{bug11825_name}>)#{bug11825_str}/
+
     assert_equal(["foo", "bar"], /(?<foo>.)(?<bar>.)/.names)
     assert_equal(["foo"], /(?<foo>.)(?<foo>.)/.names)
     assert_equal([], /(.)(.)/.names)
+    assert_equal([bug11825_name], bug11825_re.names)
 
     assert_equal(["foo", "bar"], /(?<foo>.)(?<bar>.)/.match("ab").names)
     assert_equal(["foo"], /(?<foo>.)(?<foo>.)/.match("ab").names)
     assert_equal([], /(.)(.)/.match("ab").names)
+    assert_equal([bug11825_name], bug11825_re.match(bug11825_str).names)
 
     assert_equal({"foo"=>[1], "bar"=>[2]},
                  /(?<foo>.)(?<bar>.)/.named_captures)

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

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