Project

General

Profile

Bug #11275 ยป uri-parse-query-pct-encoded.patch

jeremyevans0 (Jeremy Evans), 07/05/2019 10:00 PM

View differences:

lib/uri/generic.rb
836 836
      v.encode!(Encoding::UTF_8) rescue nil
837 837
      v.delete!("\t\r\n")
838 838
      v.force_encoding(Encoding::ASCII_8BIT)
839
      raise InvalidURIError, "invalid percent escape: #{$1}" if /(%\H\H)/n.match(v)
839 840
      v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n.freeze){'%%%02X' % $&.ord}
840 841
      v.force_encoding(Encoding::US_ASCII)
841 842
      @query = v
test/uri/test_parser.rb
40 40
		 uri_to_ary(u1))
41 41
  end
42 42

  
43
  def test_parse_query_pct_encoded
44
    assert_equal('q=%32!$&-/?.09;=:@AZ_az~', URI.parse('https://www.example.com/search?q=%32!$&-/?.09;=:@AZ_az~').query)
45
    assert_raise(URI::InvalidURIError) { URI.parse('https://www.example.com/search?q=%XX') }
46
  end
47

  
43 48
  def test_raise_bad_uri_for_integer
44 49
    assert_raise(URI::InvalidURIError) do
45 50
      URI.parse(1)