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
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
#
def url_encode(s)
s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/n) {
s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.~]/n) {
sprintf("%%%02X", $&.unpack("C")[0])
}
end
test/erb/test_erb.rb
assert_equal("%A5%B5%A5%F3%A5%D7%A5%EB",
ERB::Util.url_encode("\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB".force_encoding("EUC-JP")))
assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
ERB::Util.url_encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"),
"should not escape any unreserved characters, as per RFC3986 Section 2.3")
end
def test_percent_after_etag
    (1-1/1)