Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mlangenberg/rack
...
head fork: mlangenberg/rack
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 18 additions and 2 deletions.
  1. +13 −2 lib/rack/utils.rb
  2. +5 −0 test/spec_utils.rb
View
15 lib/rack/utils.rb
@@ -39,15 +39,26 @@ def escape_path(s)
# target encoding of the string returned, and it defaults to UTF-8
if defined?(::Encoding)
def unescape(s, encoding = Encoding::UTF_8)
- URI.decode_www_form_component(s, encoding)
+ URI.decode_www_form_component(unescape_unicode(s), encoding)
end
else
def unescape(s, encoding = nil)
- URI.decode_www_form_component(s, encoding)
+ URI.decode_www_form_component(unescape_unicode(s), encoding)
end
end
module_function :unescape
+ # See:
+ # http://en.wikipedia.org/wiki/Percent-encoding#Non-standard_implementations
+ # Issue 337
+ # Issue 360
+ def unescape_unicode(s)
+ s.gsub(/((?:%u[0-9a-fA-F]{4})+)/n){
+ [$1.delete('%u')].pack('H*').unpack("n*").pack("U*")
+ }
+ end
+ module_function :unescape_unicode
+
DEFAULT_SEP = /[&;] */n
class << self
View
5 test/spec_utils.rb
@@ -101,6 +101,11 @@ def kcodeu
should.equal "q1!2\"'w$5&7/z8)?\\"
end
+ should "unescape non-standard unicode uri escaping (e.g. ECMA-262)" do
+ Rack::Utils.unescape_unicode("%u3042").should.equal ""
+ Rack::Utils.unescape("%u3042").should.equal ""
+ end
+
should "parse query strings correctly" do
Rack::Utils.parse_query("foo=bar").
should.equal "foo" => "bar"

No commit comments for this range

Something went wrong with that request. Please try again.