classlib: throw exception from URL constructor when invalid ':' provided

This commit is contained in:
Alexey Andreev 2022-01-12 16:02:46 +03:00
parent ce5e3bfeb7
commit e4a408d26e
2 changed files with 10 additions and 1 deletions

View File

@ -72,7 +72,7 @@ public final class TURL implements Serializable {
throw new TMalformedURLException(e.toString());
}
int startIPv6Addr = spec.indexOf('[');
if (index >= 0) {
if (index > 0) {
if (startIPv6Addr == -1 || index < startIPv6Addr) {
protocol = spec.substring(0, index);
// According to RFC 2396 scheme part should match

View File

@ -228,6 +228,15 @@ public class URLTest {
} catch (MalformedURLException e) {
fail("Unexpected exception (jar protocol, relative path)" + e);
}
// no protocol
caught = false;
try {
u = new URL(":");
} catch (MalformedURLException e) {
caught = true;
}
assertTrue("7 Failed to throw MalformedURLException", caught);
}
@Test