getTargetDataFromHref: catch error if passed invalid URL

Could trigger this by typing `https://` into the internal link
annotation inspector.

Bug: T366822
Change-Id: Ie58ded247dbfb6c001d8177953ea148cd82ec03d
This commit is contained in:
David Lynch 2024-06-05 14:36:24 -05:00
parent 291844dbee
commit b10fb53f8c

View file

@ -276,7 +276,13 @@ mw.libs.ve.getTargetDataFromHref = function ( href, doc ) {
return data;
}
const url = new URL( href, doc.baseURI );
let url;
try {
url = new URL( href, doc.baseURI );
} catch ( e ) {
// An invalid URL was provided (e.g. `https://`)
return returnExternalData();
}
// Equivalent to `ve.init.platform.getExternalLinkUrlProtocolsRegExp()`, which can not be called here
const externalLinkUrlProtocolsRegExp = new RegExp( '^(' + mw.config.get( 'wgUrlProtocols' ) + ')', 'i' );