1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 06:33:23 +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:
SquidDev 2019-03-10 10:45:30 +00:00
parent 52e1906d42
commit 35ce0974cd
2 changed files with 3 additions and 0 deletions

View File

@ -113,6 +113,7 @@ public static void checkUri( URI url ) throws HTTPRequestException
{
// Validate the URL
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 );
if( !scheme.equalsIgnoreCase( "http" ) && !scheme.equalsIgnoreCase( "https" ) )

View File

@ -6,6 +6,8 @@ describe("The http library", function()
it("Rejects malformed URLs", function()
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'" })
end)