MCPcopy Create free account
hub / github.com/TruthHun/BookStack / parseUrlGroup

Method parseUrlGroup

static/katex/katex.mjs:15592–15617  ·  view source on GitHub ↗

* Parses an URL, checking escaped letters and allowed protocols.

(optional)

Source from the content-addressed store, hash-verified

15590
15591
15592 parseUrlGroup(optional) {
15593 const res = this.parseStringGroup("url", optional, true); // get raw string
15594
15595 if (!res) {
15596 return null;
15597 } // hyperref package allows backslashes alone in href, but doesn't
15598 // generate valid links in such cases; we interpret this as
15599 // "undefined" behaviour, and keep them as-is. Some browser will
15600 // replace backslashes with forward slashes.
15601
15602
15603 const url = res.text.replace(/\\([#$%&~_^{}])/g, '$1');
15604 let protocol = /^\s*([^\\/#]*?)(?::|&#0*58|&#x0*3a)/i.exec(url);
15605 protocol = protocol != null ? protocol[1] : "_relative";
15606 const allowed = this.settings.allowedProtocols;
15607
15608 if (!utils.contains(allowed, "*") && !utils.contains(allowed, protocol)) {
15609 throw new ParseError(`Forbidden protocol '${protocol}'`, res);
15610 }
15611
15612 return {
15613 type: "url",
15614 mode: this.mode,
15615 url
15616 };
15617 }
15618 /**
15619 * If `optional` is false or absent, this parses an ordinary group,
15620 * which is either a single nucleus (like "x") or an expression

Callers 3

parseGroupOfTypeMethod · 0.95
katex.jsFile · 0.80
katex.min.jsFile · 0.80

Calls 1

parseStringGroupMethod · 0.95

Tested by

no test coverage detected