Skip to content

Commit 07ae455

Browse files
committed
Updated schema location sanitizer
1 parent 9449c6e commit 07ae455

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

ts/grammar/GrammarHandler.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,15 +571,19 @@ export class GrammarHandler {
571571
return undefined;
572572
}
573573

574-
const colonIndex: number = trimmed.indexOf(':');
575-
if (colonIndex !== -1) {
576-
const scheme: string = trimmed.substring(0, colonIndex).toLowerCase();
577-
if (scheme !== 'http' && scheme !== 'https' && scheme !== 'file') {
578-
this.trace(`Rejected schema location '${trimmed}' for namespace '${namespace}' due to unsupported scheme '${scheme}'`);
574+
if (/^\w+:/.test(trimmed)) {
575+
try {
576+
const parsed = new URL(trimmed);
577+
if (!['http:', 'https:', 'file:'].includes(parsed.protocol)) {
578+
this.trace(`Rejected schema location '${trimmed}' for namespace '${namespace}' due to unsupported protocol '${parsed.protocol}'`);
579+
return undefined;
580+
}
581+
return parsed.href;
582+
} catch (error) {
583+
XMLUtils.ignoreUnused(error);
584+
this.trace(`Rejected schema location '${trimmed}' for namespace '${namespace}' because it is not a valid URL`);
579585
return undefined;
580586
}
581-
const remainder: string = trimmed.substring(colonIndex);
582-
return scheme + remainder;
583587
}
584588

585589
return trimmed;

0 commit comments

Comments
 (0)