* lib/uri/common.rb (decode_www_form_component): validate.
[ruby-dev:40938] * lib/uri/common.rb (decode_www_form): allow empty string. * lib/uri/common.rb: fix nodoc for constant. [ruby-dev:40949] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a315079390
commit
9e30f60dbf
@ -1,3 +1,12 @@
|
|||||||
|
Sun Apr 11 07:01:41 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/uri/common.rb (decode_www_form_component): validate.
|
||||||
|
[ruby-dev:40938]
|
||||||
|
|
||||||
|
* lib/uri/common.rb (decode_www_form): allow empty string.
|
||||||
|
|
||||||
|
* lib/uri/common.rb: fix nodoc for constant. [ruby-dev:40949]
|
||||||
|
|
||||||
Sat Apr 10 21:26:22 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Sat Apr 10 21:26:22 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* lib/rdoc/markup/preprocess.rb (RDoc::Markup::PreProcess#handle):
|
* lib/rdoc/markup/preprocess.rb (RDoc::Markup::PreProcess#handle):
|
||||||
|
@ -716,15 +716,10 @@ module URI
|
|||||||
DEFAULT_PARSER.make_regexp(schemes)
|
DEFAULT_PARSER.make_regexp(schemes)
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
TBLENCWWWCOMP_ = {} # :nodoc:
|
||||||
TBLENCWWWCOMP_ = {}
|
TBLDECWWWCOMP_ = {} # :nodoc:
|
||||||
|
|
||||||
# :nodoc:
|
|
||||||
TBLDECWWWCOMP_ = {}
|
|
||||||
|
|
||||||
# :nodoc:
|
|
||||||
HTML5ASCIIINCOMPAT = [Encoding::UTF_7, Encoding::UTF_16BE, Encoding::UTF_16LE,
|
HTML5ASCIIINCOMPAT = [Encoding::UTF_7, Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||||
Encoding::UTF_32BE, Encoding::UTF_32LE]
|
Encoding::UTF_32BE, Encoding::UTF_32LE] # :nodoc:
|
||||||
|
|
||||||
# Encode given +str+ to URL-encoded form data.
|
# Encode given +str+ to URL-encoded form data.
|
||||||
#
|
#
|
||||||
@ -770,6 +765,7 @@ module URI
|
|||||||
TBLDECWWWCOMP_['+'] = ' '
|
TBLDECWWWCOMP_['+'] = ' '
|
||||||
TBLDECWWWCOMP_.freeze
|
TBLDECWWWCOMP_.freeze
|
||||||
end
|
end
|
||||||
|
raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%\h\h|[^%]+)*\z/ =~ str
|
||||||
str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
|
str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -796,7 +792,7 @@ module URI
|
|||||||
if str
|
if str
|
||||||
str << '&'
|
str << '&'
|
||||||
else
|
else
|
||||||
str = ''.force_encoding(Encoding::US_ASCII)
|
str = nil.to_s
|
||||||
end
|
end
|
||||||
str << encode_www_form_component(k)
|
str << encode_www_form_component(k)
|
||||||
str << '='
|
str << '='
|
||||||
@ -805,8 +801,7 @@ module URI
|
|||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
WFKV_ = '(?:%\h\h|[^%#=;&]+)' # :nodoc:
|
||||||
WFKV_ = '(?:%\h\h|[^%#=;&])'
|
|
||||||
|
|
||||||
# Decode URL-encoded form data from given +str+.
|
# Decode URL-encoded form data from given +str+.
|
||||||
#
|
#
|
||||||
@ -829,6 +824,7 @@ module URI
|
|||||||
#
|
#
|
||||||
# See URI.decode_www_form_component, URI.encode_www_form
|
# See URI.decode_www_form_component, URI.encode_www_form
|
||||||
def self.decode_www_form(str, enc=Encoding::UTF_8)
|
def self.decode_www_form(str, enc=Encoding::UTF_8)
|
||||||
|
return [] if str.empty?
|
||||||
unless /\A#{WFKV_}*=#{WFKV_}*(?:[;&]#{WFKV_}*=#{WFKV_}*)*\z/o =~ str
|
unless /\A#{WFKV_}*=#{WFKV_}*(?:[;&]#{WFKV_}*=#{WFKV_}*)*\z/o =~ str
|
||||||
raise ArgumentError, "invalid data of application/x-www-form-urlencoded (#{str})"
|
raise ArgumentError, "invalid data of application/x-www-form-urlencoded (#{str})"
|
||||||
end
|
end
|
||||||
|
@ -69,6 +69,7 @@ class TestCommon < Test::Unit::TestCase
|
|||||||
"AZ%5B%5C%5D%5E_%60az%7B%7C%7D%7E"))
|
"AZ%5B%5C%5D%5E_%60az%7B%7C%7D%7E"))
|
||||||
assert_equal("\xA1\xA2".force_encoding(Encoding::EUC_JP),
|
assert_equal("\xA1\xA2".force_encoding(Encoding::EUC_JP),
|
||||||
URI.decode_www_form_component("%A1%A2", "EUC-JP"))
|
URI.decode_www_form_component("%A1%A2", "EUC-JP"))
|
||||||
|
assert_raise(ArgumentError){URI.decode_www_form_component("%")}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_encode_www_form
|
def test_encode_www_form
|
||||||
@ -88,6 +89,7 @@ class TestCommon < Test::Unit::TestCase
|
|||||||
assert_equal([%w[a 1], ["\u3042", "\u6F22"]],
|
assert_equal([%w[a 1], ["\u3042", "\u6F22"]],
|
||||||
URI.decode_www_form("a=1;%E3%81%82=%E6%BC%A2"))
|
URI.decode_www_form("a=1;%E3%81%82=%E6%BC%A2"))
|
||||||
assert_equal([%w[?a 1], %w[a 2]], URI.decode_www_form("?a=1&a=2"))
|
assert_equal([%w[?a 1], %w[a 2]], URI.decode_www_form("?a=1&a=2"))
|
||||||
|
assert_equal([], URI.decode_www_form(""))
|
||||||
assert_raise(ArgumentError){URI.decode_www_form("%=1")}
|
assert_raise(ArgumentError){URI.decode_www_form("%=1")}
|
||||||
assert_raise(ArgumentError){URI.decode_www_form("a=%")}
|
assert_raise(ArgumentError){URI.decode_www_form("a=%")}
|
||||||
assert_raise(ArgumentError){URI.decode_www_form("a=1&%=2")}
|
assert_raise(ArgumentError){URI.decode_www_form("a=1&%=2")}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user