diff options
Diffstat (limited to 'app/lib/request.rb')
-rw-r--r-- | app/lib/request.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/lib/request.rb b/app/lib/request.rb index e3597b052f6..adc9a48f3dd 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -76,8 +76,8 @@ class Request HTTP::URI.new( scheme: uri.normalized_scheme, authority: uri.normalized_authority, - path: Addressable::URI.normalize_path(uri.path), - query: uri.query + path: Addressable::URI.normalize_path(encode_non_ascii(uri.path)).presence || '/', + query: encode_non_ascii(uri.query) ) end @@ -151,6 +151,12 @@ class Request %w(http https).include?(parsed_url.scheme) && parsed_url.host.present? end + NON_ASCII_PATTERN = /[^\x00-\x7F]+/ + + def encode_non_ascii(str) + str&.gsub(NON_ASCII_PATTERN) { |substr| CGI.escape(substr.encode(Encoding::UTF_8)) } + end + def http_client HTTP.use(:auto_inflate).use(normalize_uri: { normalizer: URI_NORMALIZER }).follow(max_hops: 3) end |