mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-11 00:20:05 +00:00
Fix NPE when checking URLs
If the host was null due to a malformed URL, we'd try to verify that it was allowed, throwing an NPE. Fixes #135
This commit is contained in:
parent
52e1906d42
commit
35ce0974cd
@ -113,6 +113,7 @@ public class HttpRequest extends Resource<HttpRequest>
|
|||||||
{
|
{
|
||||||
// Validate the URL
|
// Validate the URL
|
||||||
if( url.getScheme() == null ) throw new HTTPRequestException( "Must specify http or https" );
|
if( url.getScheme() == null ) throw new HTTPRequestException( "Must specify http or https" );
|
||||||
|
if( url.getHost() == null ) throw new HTTPRequestException( "URL malformed" );
|
||||||
|
|
||||||
String scheme = url.getScheme().toLowerCase( Locale.ROOT );
|
String scheme = url.getScheme().toLowerCase( Locale.ROOT );
|
||||||
if( !scheme.equalsIgnoreCase( "http" ) && !scheme.equalsIgnoreCase( "https" ) )
|
if( !scheme.equalsIgnoreCase( "http" ) && !scheme.equalsIgnoreCase( "https" ) )
|
||||||
|
@ -6,6 +6,8 @@ describe("The http library", function()
|
|||||||
|
|
||||||
it("Rejects malformed URLs", function()
|
it("Rejects malformed URLs", function()
|
||||||
expect({ http.checkURL("google.com")}):same({ false, "Must specify http or https" })
|
expect({ http.checkURL("google.com")}):same({ false, "Must specify http or https" })
|
||||||
|
expect({ http.checkURL("https:google.com")}):same({ false, "URL malformed" })
|
||||||
|
expect({ http.checkURL("https:/google.com")}):same({ false, "URL malformed" })
|
||||||
expect({ http.checkURL("wss://google.com")}):same({ false, "Invalid protocol 'wss'" })
|
expect({ http.checkURL("wss://google.com")}):same({ false, "Invalid protocol 'wss'" })
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user