2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-31 14:05:14 +00:00

Immediately check url scheme in lib/download.

This commit is contained in:
Edho Arief
2012-11-17 05:58:03 -08:00
parent bfde63f92b
commit 75a1f0b3cd

View File

@@ -28,16 +28,17 @@ module Danbooru
while true
url = Addressable::URI.parse(source)
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
if url.request_uri.match /[^!*'();:@&=+$,\/?#\[\]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\-_.~%]/
url.path = Addressable::URI.encode(url.path)
url.query = Addressable::URI.encode(url.query)
end
unless url.scheme == 'http' or url.scheme == 'https'
raise SocketError, "URL must be HTTP or HTTPS"
end
unless url.port
url.port = url.scheme == 'https' ? 443 : 80
end