mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Move escape_uri method to a more suitable place
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user