mirror of
https://github.com/moebooru/moebooru
synced 2025-09-03 23:45:12 +00:00
Immediately check url scheme in lib/download.
This commit is contained in:
@@ -28,16 +28,17 @@ module Danbooru
|
|||||||
while true
|
while true
|
||||||
url = Addressable::URI.parse(source)
|
url = Addressable::URI.parse(source)
|
||||||
url.host = url.normalized_host
|
url.host = url.normalized_host
|
||||||
|
|
||||||
|
unless url.scheme == 'http' or url.scheme == 'https'
|
||||||
|
raise SocketError, "URL must be HTTP or HTTPS"
|
||||||
|
end
|
||||||
|
|
||||||
# check if the request uri is not percent-encoded
|
# check if the request uri is not percent-encoded
|
||||||
if url.request_uri.match /[^!*'();:@&=+$,\/?#\[\]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-_.~%]/
|
if url.request_uri.match /[^!*'();:@&=+$,\/?#\[\]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-_.~%]/
|
||||||
url.path = Addressable::URI.encode(url.path)
|
url.path = Addressable::URI.encode(url.path)
|
||||||
url.query = Addressable::URI.encode(url.query)
|
url.query = Addressable::URI.encode(url.query)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless url.scheme == 'http' or url.scheme == 'https'
|
|
||||||
raise SocketError, "URL must be HTTP or HTTPS"
|
|
||||||
end
|
|
||||||
|
|
||||||
unless url.port
|
unless url.port
|
||||||
url.port = url.scheme == 'https' ? 443 : 80
|
url.port = url.scheme == 'https' ? 443 : 80
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user