Move escape_uri method to a more suitable place

This commit is contained in:
Gerhard Schlager
2017-12-12 17:50:39 +01:00
parent 5fbfe34356
commit e30851e45a
5 changed files with 38 additions and 35 deletions

View File

@@ -21,4 +21,14 @@ class UrlHelper
url.sub(/^http:/i, "")
end
DOUBLE_ESCAPED_REGEXP ||= /%25([0-9a-f]{2})/i
# Prevents double URL encode
# https://stackoverflow.com/a/37599235
def self.escape_uri(uri, pattern = URI::UNSAFE)
encoded = URI.encode(uri, pattern)
encoded.gsub!(DOUBLE_ESCAPED_REGEXP, '%\1')
encoded
end
end