mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2bded596ec
commit
682f3a7881
2 changed files with 4 additions and 1 deletions
|
@ -379,7 +379,7 @@ module URI
|
|||
#
|
||||
# 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
|
||||
|
||||
|
|
|
@ -100,6 +100,9 @@ class TestCommon < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue