Project

General

Profile

Bug #6696 ยป erb_util_url_encode_rfc_fix.patch

madeofcode (Mark Dodwell), 07/04/2012 05:03 PM

View differences:

lib/erb.rb
928 928
    #   Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
929 929
    #
930 930
    def url_encode(s)
931
      s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/n) {
931
      s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.~]/n) {
932 932
        sprintf("%%%02X", $&.unpack("C")[0])
933 933
      }
934 934
    end
test/erb/test_erb.rb
441 441

  
442 442
    assert_equal("%A5%B5%A5%F3%A5%D7%A5%EB",
443 443
                 ERB::Util.url_encode("\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB".force_encoding("EUC-JP")))
444

  
445
    assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
446
                 ERB::Util.url_encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"),
447
                 "should not escape any unreserved characters, as per RFC3986 Section 2.3")
444 448
  end
445 449

  
446 450
  def test_percent_after_etag
447
-