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

ruby-changes:27806

From: nobu <ko1@a...>
Date: Thu, 21 Mar 2013 16:48:34 +0900 (JST)
Subject: [ruby-changes:27806] nobu:r39858 (trunk): parse.y: escape all closing parens

nobu	2013-03-21 16:48:11 +0900 (Thu, 21 Mar 2013)

  New Revision: 39858

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

  Log:
    parse.y: escape all closing parens
    
    * parse.y (simple_re_meta): escape all closing characters, not only
      round parenthesis.  [ruby-core:53578] [Bug #8133]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_regexp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39857)
+++ ChangeLog	(revision 39858)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Mar 21 16:48:06 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (simple_re_meta): escape all closing characters, not only
+	  round parenthesis.  [ruby-core:53578] [Bug #8133]
+
 Thu Mar 21 13:50:46 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_core.h (UNINITIALIZED_VAR): suppress warnings by clang 4.2.
Index: parse.y
===================================================================
--- parse.y	(revision 39857)
+++ parse.y	(revision 39858)
@@ -5994,7 +5994,7 @@ simple_re_meta(int c) https://github.com/ruby/ruby/blob/trunk/parse.y#L5994
     switch (c) {
       case '$': case '*': case '+': case '.':
       case '?': case '^': case '|':
-      case ')':
+      case ')': case ']': case '}': case '>':
 	return TRUE;
       default:
 	return FALSE;
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 39857)
+++ test/ruby/test_regexp.rb	(revision 39858)
@@ -180,9 +180,15 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L180
   end
 
   def test_source_escaped_paren
-    bug7610 = '[ruby-core:51088]'
-    s = '\(a\)'
-    assert_equal(/#{s}/, eval("%r(#{s})"), bug7610)
+    bug7610 = '[ruby-core:51088] [Bug #7610]'
+    bug8133 = '[ruby-core:53578] [Bug #8133]'
+    [
+     ["(", ")", bug7610], ["[", "]", bug8133],
+     ["{", "}", bug8133], ["<", ">", bug8133],
+    ].each do |lparen, rparen, bug|
+      s = "\\#{lparen}a\\#{rparen}"
+      assert_equal(/#{s}/, eval("%r#{lparen}#{s}#{rparen}"), bug)
+    end
   end
 
   def test_source_unescaped

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

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