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

ruby-changes:54255

From: nobu <ko1@a...>
Date: Thu, 20 Dec 2018 14:43:21 +0900 (JST)
Subject: [ruby-changes:54255] nobu:r66463 (trunk): parse.y: ignore constant name captures

nobu	2018-12-20 14:43:15 +0900 (Thu, 20 Dec 2018)

  New Revision: 66463

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

  Log:
    parse.y: ignore constant name captures
    
    * parse.y (reg_named_capture_assign_iter): ignore non-local name
      captures, including non-ASCII constant names.
      [ruby-dev:50719] [Bug #15437]

  Modified files:
    trunk/parse.y
    trunk/symbol.c
    trunk/symbol.h
    trunk/test/ruby/test_regexp.rb
Index: symbol.c
===================================================================
--- symbol.c	(revision 66462)
+++ symbol.c	(revision 66463)
@@ -238,7 +238,7 @@ rb_sym_constant_char_p(const char *name, https://github.com/ruby/ruby/blob/trunk/symbol.c#L238
 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
 #define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
 
-static int
+int
 rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
 {
     const char *m = name;
Index: symbol.h
===================================================================
--- symbol.h	(revision 66462)
+++ symbol.h	(revision 66463)
@@ -98,6 +98,8 @@ is_global_name_punct(const int c) https://github.com/ruby/ruby/blob/trunk/symbol.h#L98
     return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
 }
 
+int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset);
+
 RUBY_SYMBOL_EXPORT_BEGIN
 
 size_t rb_sym_immortal_count(void);
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 66462)
+++ test/ruby/test_regexp.rb	(revision 66463)
@@ -216,6 +216,12 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L216
     assert_not_include(local_variables, :nil, "[ruby-dev:32675]")
   end
 
+  def test_assign_named_capture_to_const
+    %W[C \u{1d402}].each do |name|
+      assert_equal(:ok, Class.new.class_eval("#{name} = :ok; /(?<#{name}>.*)/ =~ 'ng'; #{name}"))
+    end
+  end
+
   def test_assign_named_capture_trace
     bug = '[ruby-core:79940] [Bug #13287]'
     assert_normal_exit("#{<<-"begin;"}\n#{<<-"end;"}", bug)
Index: parse.y
===================================================================
--- parse.y	(revision 66462)
+++ parse.y	(revision 66463)
@@ -10669,11 +10669,12 @@ reg_named_capture_assign_iter(const Onig https://github.com/ruby/ruby/blob/trunk/parse.y#L10669
     ID var;
     NODE *node, *succ;
 
-    if (!len || (*name != '_' && ISASCII(*name) && !rb_enc_islower(*name, enc)) ||
-	(len < MAX_WORD_LENGTH && rb_reserved_word(s, (int)len)) ||
-	!rb_enc_symname2_p(s, len, enc)) {
+    if (!len) return ST_CONTINUE;
+    if (len < MAX_WORD_LENGTH && rb_reserved_word(s, (int)len))
         return ST_CONTINUE;
-    }
+    if (rb_enc_symname_type(s, len, enc, (1U<<ID_LOCAL)) != ID_LOCAL)
+        return ST_CONTINUE;
+
     var = intern_cstr(s, len, enc);
     node = node_assign(p, assignable(p, var, 0, arg->loc), NEW_LIT(ID2SYM(var), arg->loc), arg->loc);
     succ = arg->succ_block;

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

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