Bug #8612 » ruby_2_0_0_url_encode_issue.patch
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
|