Skip to content

Commit

Permalink
Maintain original encoding from path
Browse files Browse the repository at this point in the history
When the path info is read from the socket it's encoded as ASCII 8BIT.
The unescape method changes the encoding to UTF8 but it should maintain
the encoding of the string that's passed in.

This causes parameters to be force encoded to UTF8 when we don't
actually know what the encoding of the parameter should be.
  • Loading branch information
eileencodes committed Aug 3, 2017
1 parent a47be5a commit 620d40b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/lib/action_dispatch/journey/router/utils.rb
Expand Up @@ -13,11 +13,13 @@ class Utils # :nodoc:
# normalize_path("") # => "/"
# normalize_path("/%ab") # => "/%AB"
def self.normalize_path(path)
encoding = path.encoding
path = "/#{path}"
path.squeeze!("/".freeze)
path.sub!(%r{/+\Z}, "".freeze)
path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase }
path = "/" if path == "".freeze
path.force_encoding(encoding)
path
end

Expand Down
5 changes: 5 additions & 0 deletions actionpack/test/journey/router/utils_test.rb
Expand Up @@ -31,6 +31,11 @@ def test_normalize_path_not_greedy
def test_normalize_path_uppercase
assert_equal "/foo%AAbar%AAbaz", Utils.normalize_path("/foo%aabar%aabaz")
end

def test_normalize_path_maintains_string_encoding
path = "/foo%AAbar%AAbaz".b
assert_equal Encoding::ASCII_8BIT, Utils.normalize_path(path).encoding
end
end
end
end
Expand Down

0 comments on commit 620d40b

Please sign in to comment.