diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2014-07-10 10:47:56 +0100 |
---|---|---|
committer | Andrew White <pixeltrix@users.noreply.github.com> | 2014-07-10 10:47:56 +0100 |
commit | 6b6832eeeb43c5f2553373f84677350ba654346a (patch) | |
tree | b7e194b25eda53d87edf429f3ef1ed51e1007804 /actionpack/lib/action_dispatch | |
parent | b9ffae8feb453ee2961b5284fe3310b227532179 (diff) | |
parent | 8a297131349bf4e0ade4a0941e5da0c987396d89 (diff) | |
download | rails-6b6832eeeb43c5f2553373f84677350ba654346a.tar.gz rails-6b6832eeeb43c5f2553373f84677350ba654346a.tar.bz2 rails-6b6832eeeb43c5f2553373f84677350ba654346a.zip |
Merge pull request #16123 from karlentwistle/issues/9299
Force encoding of US-ASCII to UTF-8 in unescape_uri.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/router/utils.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb index ac4ecb1e65..2b0a6575d4 100644 --- a/actionpack/lib/action_dispatch/journey/router/utils.rb +++ b/actionpack/lib/action_dispatch/journey/router/utils.rb @@ -25,9 +25,10 @@ module ActionDispatch # http://tools.ietf.org/html/rfc3986 class UriEncoder # :nodoc: ENCODE = "%%%02X".freeze - ENCODING = Encoding::US_ASCII - EMPTY = "".force_encoding(ENCODING).freeze - DEC2HEX = (0..255).to_a.map{ |i| ENCODE % i }.map{ |s| s.force_encoding(ENCODING) } + US_ASCII = Encoding::US_ASCII + UTF_8 = Encoding::UTF_8 + EMPTY = "".force_encoding(US_ASCII).freeze + DEC2HEX = (0..255).to_a.map{ |i| ENCODE % i }.map{ |s| s.force_encoding(US_ASCII) } ALPHA = "a-zA-Z".freeze DIGIT = "0-9".freeze @@ -53,12 +54,13 @@ module ActionDispatch end def unescape_uri(uri) - uri.gsub(ESCAPED) { [$&[1, 2].hex].pack('C') }.force_encoding(uri.encoding) + encoding = uri.encoding == US_ASCII ? UTF_8 : uri.encoding + uri.gsub(ESCAPED) { [$&[1, 2].hex].pack('C') }.force_encoding(encoding) end protected def escape(component, pattern) - component.gsub(pattern){ |unsafe| percent_encode(unsafe) }.force_encoding(ENCODING) + component.gsub(pattern){ |unsafe| percent_encode(unsafe) }.force_encoding(US_ASCII) end def percent_encode(unsafe) |