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
1 parent e0ce15f commit a2b2161834aad1a4c0710f9b1dfd5e2b21f98f7e
@@ -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!('/')
path.sub!(%r{/+\Z}, '')
path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase }
path = '/' if path == ''
path = "/" if path == "".freeze
path.force_encoding(encoding)
path
end
@@ -32,6 +32,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 a2b2161

Please sign in to comment.