Project

General

Profile

Bug #8612 » ruby_1_9_3_url_encode_issue.patch

Ruby 1.9.3 patch for ERB::Util.url_encode - fotos (Fotos Georgiadis), 07/09/2013 12:58 AM

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) {
sprintf("%%%02X", $&.unpack("C")[0])
s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/n) { |m|
sprintf("%%%02X", m.unpack("C")[0])
}
end
alias u url_encode
test/erb/test_erb.rb
end
class TestERBCore < Test::Unit::TestCase
class MyString < String
def to_s
self
end
def gsub(*args, &block)
to_str.gsub(*args, &block)
end
end
def setup
@erb = ERB
end
......
ERB::Util.url_encode("\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB".force_encoding("EUC-JP")))
end
def test_url_encode_string_subclass
string = "\xCE\x94\xCE\xBF\xCE\xBA\xCE\xB9\xCE\xBC\xCE\xAE".force_encoding("UTF-8")
assert_equal("%CE%94%CE%BF%CE%BA%CE%B9%CE%BC%CE%AE",
ERB::Util.url_encode(string))
assert_equal("%CE%94%CE%BF%CE%BA%CE%B9%CE%BC%CE%AE",
ERB::Util.url_encode(MyString.new(string)))
end
def test_percent_after_etag
assert_equal("1%", @erb.new("<%= 1 %>%", nil, "%").result)
end
(1-1/4)