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

ruby-changes:35191

From: nobu <ko1@a...>
Date: Mon, 25 Aug 2014 16:29:59 +0900 (JST)
Subject: [ruby-changes:35191] nobu:r47273 (trunk): uri/common.rb: use negative look-ahead

nobu	2014-08-25 16:29:50 +0900 (Mon, 25 Aug 2014)

  New Revision: 47273

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

  Log:
    uri/common.rb: use negative look-ahead
    
    * lib/uri/common.rb (URI.decode_www_form_component): use negative
      look-ahead instead of nested repeat operators, to get rid of
      backtrack explosion.

  Modified files:
    trunk/lib/uri/common.rb
    trunk/test/uri/test_common.rb
Index: lib/uri/common.rb
===================================================================
--- lib/uri/common.rb	(revision 47272)
+++ lib/uri/common.rb	(revision 47273)
@@ -379,7 +379,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L379
   #
   # See URI.encode_www_form_component, URI.decode_www_form
   def self.decode_www_form_component(str, enc=Encoding::UTF_8)
-    raise ArgumentError, "invalid %-encoding (#{str})" unless /\A[^%]*(?:%\h\h[^%]*)*\z/ =~ str
+    raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
     str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
   end
 
Index: test/uri/test_common.rb
===================================================================
--- test/uri/test_common.rb	(revision 47272)
+++ test/uri/test_common.rb	(revision 47273)
@@ -100,6 +100,9 @@ class TestCommon < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_common.rb#L100
                  URI.decode_www_form_component("\xE3\x81\x82%E3%81%82".force_encoding("UTF-8")))
 
     assert_raise(ArgumentError){URI.decode_www_form_component("%")}
+    assert_raise(ArgumentError){URI.decode_www_form_component("%a")}
+    assert_raise(ArgumentError){URI.decode_www_form_component("x%a_")}
+    assert_nothing_raised(ArgumentError){URI.decode_www_form_component("x"*(1024*1024))}
   end
 
   def test_encode_www_form

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

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