Fix request URL normalisation for bare domain and 8-bit characters (#26285)
This commit is contained in:
parent
2cbdff97ce
commit
8891d8945d
2 changed files with 68 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue