summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-17 11:58:09 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-17 11:58:09 +0000
commit53127c2410c29f7cc942a76baa7be97ba65aafda (patch)
tree2216e7b11eb1b4b2d43602a3b4327122c225bcfb
parent95d3671e94515fa83de975604fd1a03fa79f081b (diff)
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
-rw-r--r--lib/erb.rb2
-rw-r--r--test/erb/test_erb.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/erb.rb b/lib/erb.rb
index ab65ef3be55..ae2bfd00914 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -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
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index 6a07f9c5cbc..7a92de36309 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -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