diff options
-rw-r--r-- | lib/uri/common.rb | 41 | ||||
-rw-r--r-- | lib/uri/generic.rb | 14 | ||||
-rw-r--r-- | test/uri/test_common.rb | 52 | ||||
-rw-r--r-- | test/uri/test_parser.rb | 9 |
4 files changed, 106 insertions, 10 deletions
@@ -295,6 +295,7 @@ module URI 256.times do |i| TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i) end TBLENCWWWCOMP_[' '] = '+' TBLENCWWWCOMP_.freeze TBLDECWWWCOMP_ = {} # :nodoc: @@ -320,6 +321,33 @@ module URI # # See URI.decode_www_form_component, URI.encode_www_form. def self.encode_www_form_component(str, enc=nil) str = str.to_s.dup if str.encoding != Encoding::ASCII_8BIT if enc && enc != Encoding::ASCII_8BIT @@ -328,19 +356,16 @@ module URI end str.force_encoding(Encoding::ASCII_8BIT) end - str.gsub!(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_) str.force_encoding(Encoding::US_ASCII) end - # Decodes given +str+ of URL-encoded form data. - # - # This decodes + to SP. - # - # 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)/.match?(str) - str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc) end # Generates URL-encoded form data from given +enum+. # @@ -564,16 +564,26 @@ module URI end end - # Returns the user component. def user @user end - # Returns the password component. def password @password end # # Checks the host +v+ component for RFC2396 compliance # and against the URI::Parser Regexp for :HOST. @@ -130,6 +130,58 @@ class TestCommon < Test::Unit::TestCase assert_nothing_raised(ArgumentError){URI.decode_www_form_component("x"*(1024*1024))} end def test_encode_www_form assert_equal("a=1", URI.encode_www_form("a" => "1")) assert_equal("a=1", URI.encode_www_form(a: 1)) @@ -50,6 +50,15 @@ class URI::TestParser < Test::Unit::TestCase assert_raise(URI::InvalidURIError) { URI.parse('https://www.example.com/search?q=%XX') } end def test_raise_bad_uri_for_integer assert_raise(URI::InvalidURIError) do URI.parse(1) |