Permalink
Browse files

Merge pull request #29062 from eileencodes/force-encoding-to-original…

…-string-encoding

Maintain original encoding from path
  • Loading branch information...
eileencodes committed May 12, 2017
2 parents b30760a + 8607c25 commit 276bfa7fc6efb0cea4408fe9f97b8741737b7549
@@ -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
@@ -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

0 comments on commit 276bfa7

Please sign in to comment.