summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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