Feature #10503 ยป raise_invalid_percent_encoding_error.diff
lib/uri/common.rb (working copy) | ||
---|---|---|
# URI is valid, bad usage is not.
|
||
#
|
||
class BadURIError < Error; end
|
||
#
|
||
# The "%"-encoding of a URI part is invalid
|
||
#
|
||
class InvalidPercentEncoding < ArgumentError; end
|
||
#
|
||
# == Synopsis
|
||
... | ... | |
#
|
||
# 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})" if /%(?!\h\h)/ =~ str
|
||
raise InvalidPercentEncoding, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
|
||
str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
|
||
end
|
||
test/uri/test_common.rb (working copy) | ||
---|---|---|
assert_equal("\xE3\x81\x82\xE3\x81\x82".force_encoding("UTF-8"),
|
||
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))}
|
||
assert_raise(InvalidPercentEncoding){URI.decode_www_form_component("%")}
|
||
assert_raise(InvalidPercentEncoding){URI.decode_www_form_component("%a")}
|
||
assert_raise(InvalidPercentEncoding){URI.decode_www_form_component("x%a_")}
|
||
assert_nothing_raised(InvalidPercentEncoding){URI.decode_www_form_component("x"*(1024*1024))}
|
||
end
|
||
def test_encode_www_form
|