1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

erb.rb: Don't encode tilde in #url_encode

Based on patch by madeofcode (Mark Dodwell).
[ruby-core:46168] [Bug #6696] [Fix GH-54]

`~` is a unreserved character.
https://tools.ietf.org/html/rfc3986#section-2.3

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2017-05-17 11:58:09 +00:00
parent 95d3671e94
commit 53127c2410
2 changed files with 5 additions and 1 deletions

View file

@ -994,7 +994,7 @@ class ERB
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
#
def url_encode(s)
s.to_s.b.gsub(/[^a-zA-Z0-9_\-.]/n) { |m|
s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m|
sprintf("%%%02X", m.unpack("C")[0])
}
end

View file

@ -464,6 +464,10 @@ EOS
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