Project

General

Profile

Feature #10503 ยป raise_invalid_percent_encoding_error.diff

jackdanger (Jack Danger), 11/13/2014 12:06 AM

View differences:

lib/uri/common.rb (working copy)
152 152
  # URI is valid, bad usage is not.
153 153
  #
154 154
  class BadURIError < Error; end
155
  #
156
  # The "%"-encoding of a URI part is invalid
157
  #
158
  class InvalidPercentEncoding < ArgumentError; end
155 159

  
156 160
  #
157 161
  # == Synopsis
......
379 383
  #
380 384
  # See URI.encode_www_form_component, URI.decode_www_form
381 385
  def self.decode_www_form_component(str, enc=Encoding::UTF_8)
382
    raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
386
    raise InvalidPercentEncoding, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
383 387
    str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
384 388
  end
385 389

  
test/uri/test_common.rb (working copy)
99 99
    assert_equal("\xE3\x81\x82\xE3\x81\x82".force_encoding("UTF-8"),
100 100
                 URI.decode_www_form_component("\xE3\x81\x82%E3%81%82".force_encoding("UTF-8")))
101 101

  
102
    assert_raise(ArgumentError){URI.decode_www_form_component("%")}
103
    assert_raise(ArgumentError){URI.decode_www_form_component("%a")}
104
    assert_raise(ArgumentError){URI.decode_www_form_component("x%a_")}
105
    assert_nothing_raised(ArgumentError){URI.decode_www_form_component("x"*(1024*1024))}
102
    assert_raise(InvalidPercentEncoding){URI.decode_www_form_component("%")}
103
    assert_raise(InvalidPercentEncoding){URI.decode_www_form_component("%a")}
104
    assert_raise(InvalidPercentEncoding){URI.decode_www_form_component("x%a_")}
105
    assert_nothing_raised(InvalidPercentEncoding){URI.decode_www_form_component("x"*(1024*1024))}
106 106
  end
107 107

  
108 108
  def test_encode_www_form