aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2017-05-12 14:58:46 -0400
committerGitHub <noreply@github.com>2017-05-12 14:58:46 -0400
commit276bfa7fc6efb0cea4408fe9f97b8741737b7549 (patch)
tree0c8f2613b1c4507905a57e3b580b4e0bb4e92aca /actionpack
parentb30760a4846d04bc48c787c95013208950906f5e (diff)
parent8607c25ba7810573733d9b37d0015154ba059f5e (diff)
downloadrails-276bfa7fc6efb0cea4408fe9f97b8741737b7549.tar.gz
rails-276bfa7fc6efb0cea4408fe9f97b8741737b7549.tar.bz2
rails-276bfa7fc6efb0cea4408fe9f97b8741737b7549.zip
Merge pull request #29062 from eileencodes/force-encoding-to-original-string-encoding
Maintain original encoding from path
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/journey/router/utils.rb2
-rw-r--r--actionpack/test/journey/router/utils_test.rb5
2 files changed, 7 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/journey/router/utils.rb b/actionpack/lib/action_dispatch/journey/router/utils.rb
index e624b4c80d..6d400f3364 100644
--- a/actionpack/lib/action_dispatch/journey/router/utils.rb
+++ b/actionpack/lib/action_dispatch/journey/router/utils.rb
@@ -13,11 +13,13 @@ module ActionDispatch
# 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
diff --git a/actionpack/test/journey/router/utils_test.rb b/actionpack/test/journey/router/utils_test.rb
index b77bf6628a..74277a4325 100644
--- a/actionpack/test/journey/router/utils_test.rb
+++ b/actionpack/test/journey/router/utils_test.rb
@@ -31,6 +31,11 @@ module ActionDispatch
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