nexum-code 0.15.1 → 0.18.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/XMLParser-DFAnGqkc.mjs +3956 -0
- package/dist/{app-5jOmOWG7.mjs → app-aqWxJw2S.mjs} +15153 -10822
- package/dist/{dispatch-DA_D42qp.mjs → dispatch-ByfuGE0h.mjs} +1 -1
- package/dist/{dispatch-C98jHQkj.mjs → dispatch-DQ6ufFQt.mjs} +38604 -29700
- package/dist/main.mjs +1 -1
- package/dist/{markit-DG5XsAGz.mjs → markit-XGWU21rO.mjs} +65 -3926
- package/dist/public/assets/astro-DAp21e1Q.js +2 -0
- package/dist/public/assets/astro-DAp21e1Q.js.map +1 -0
- package/dist/public/assets/bash-Yzrsuije.js +2 -0
- package/dist/public/assets/bash-Yzrsuije.js.map +1 -0
- package/dist/public/assets/c-BIGW1oBm.js +2 -0
- package/dist/public/assets/c-BIGW1oBm.js.map +1 -0
- package/dist/public/assets/cpp-BRuaLJcg.js +2 -0
- package/dist/public/assets/cpp-BRuaLJcg.js.map +1 -0
- package/dist/public/assets/csharp-COcwbKMJ.js +2 -0
- package/dist/public/assets/csharp-COcwbKMJ.js.map +1 -0
- package/dist/public/assets/css-DEUVOdPa.js +2 -0
- package/dist/public/assets/css-DEUVOdPa.js.map +1 -0
- package/dist/public/assets/dart-CF10PKvl.js +2 -0
- package/dist/public/assets/dart-CF10PKvl.js.map +1 -0
- package/dist/public/assets/docker-BcOcwvcX.js +2 -0
- package/dist/public/assets/docker-BcOcwvcX.js.map +1 -0
- package/dist/public/assets/go-CxLEBnE3.js +2 -0
- package/dist/public/assets/go-CxLEBnE3.js.map +1 -0
- package/dist/public/assets/graphql-ChdNCCLP.js +2 -0
- package/dist/public/assets/graphql-ChdNCCLP.js.map +1 -0
- package/dist/public/assets/html-CNxCFRDw.js +2 -0
- package/dist/public/assets/html-CNxCFRDw.js.map +1 -0
- package/dist/public/assets/index-BfTRKbmy.css +1 -0
- package/dist/public/assets/index-C28kWE_L.js +240 -0
- package/dist/public/assets/index-C28kWE_L.js.map +1 -0
- package/dist/public/assets/ini-BEwlwnbL.js +2 -0
- package/dist/public/assets/ini-BEwlwnbL.js.map +1 -0
- package/dist/public/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/dist/public/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/dist/public/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/dist/public/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/dist/public/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/dist/public/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/dist/public/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/dist/public/assets/java-CylS5w8V.js +2 -0
- package/dist/public/assets/java-CylS5w8V.js.map +1 -0
- package/dist/public/assets/javascript-wDzz0qaB.js +2 -0
- package/dist/public/assets/javascript-wDzz0qaB.js.map +1 -0
- package/dist/public/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/public/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/public/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/public/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/public/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/public/assets/json-Cp-IABpG.js +2 -0
- package/dist/public/assets/json-Cp-IABpG.js.map +1 -0
- package/dist/public/assets/jsx-g9-lgVsj.js +2 -0
- package/dist/public/assets/jsx-g9-lgVsj.js.map +1 -0
- package/dist/public/assets/kotlin-BdnUsdx6.js +2 -0
- package/dist/public/assets/kotlin-BdnUsdx6.js.map +1 -0
- package/dist/public/assets/lua-BaeVxFsk.js +2 -0
- package/dist/public/assets/lua-BaeVxFsk.js.map +1 -0
- package/dist/public/assets/make-CHLpvVh8.js +2 -0
- package/dist/public/assets/make-CHLpvVh8.js.map +1 -0
- package/dist/public/assets/markdown-Cvjx9yec.js +2 -0
- package/dist/public/assets/markdown-Cvjx9yec.js.map +1 -0
- package/dist/public/assets/perl-CptaX86O.js +2 -0
- package/dist/public/assets/perl-CptaX86O.js.map +1 -0
- package/dist/public/assets/postcss-DnzrXTVv.js +2 -0
- package/dist/public/assets/postcss-DnzrXTVv.js.map +1 -0
- package/dist/public/assets/protobuf-C7zT0LnQ.js +2 -0
- package/dist/public/assets/protobuf-C7zT0LnQ.js.map +1 -0
- package/dist/public/assets/python-B6aJPvgy.js +2 -0
- package/dist/public/assets/python-B6aJPvgy.js.map +1 -0
- package/dist/public/assets/r-Dspwwk_N.js +2 -0
- package/dist/public/assets/r-Dspwwk_N.js.map +1 -0
- package/dist/public/assets/ruby-CcrC3V9I.js +2 -0
- package/dist/public/assets/ruby-CcrC3V9I.js.map +1 -0
- package/dist/public/assets/rust-B1yitclQ.js +2 -0
- package/dist/public/assets/rust-B1yitclQ.js.map +1 -0
- package/dist/public/assets/scala-C151Ov-r.js +2 -0
- package/dist/public/assets/scala-C151Ov-r.js.map +1 -0
- package/dist/public/assets/sql-BLtJtn59.js +2 -0
- package/dist/public/assets/sql-BLtJtn59.js.map +1 -0
- package/dist/public/assets/svelte-U4fHntn6.js +2 -0
- package/dist/public/assets/svelte-U4fHntn6.js.map +1 -0
- package/dist/public/assets/swift-D82vCrfD.js +2 -0
- package/dist/public/assets/swift-D82vCrfD.js.map +1 -0
- package/dist/public/assets/toml-vGWfd6FD.js +2 -0
- package/dist/public/assets/toml-vGWfd6FD.js.map +1 -0
- package/dist/public/assets/tsx-COt5Ahok.js +2 -0
- package/dist/public/assets/tsx-COt5Ahok.js.map +1 -0
- package/dist/public/assets/typescript-BPQ3VLAy.js +2 -0
- package/dist/public/assets/typescript-BPQ3VLAy.js.map +1 -0
- package/dist/public/assets/xml-sdJ4AIDG.js +2 -0
- package/dist/public/assets/xml-sdJ4AIDG.js.map +1 -0
- package/dist/public/assets/yaml-Buea-lGh.js +2 -0
- package/dist/public/assets/yaml-Buea-lGh.js.map +1 -0
- package/dist/public/gateway.html +156 -156
- package/dist/public/index.html +2 -2
- package/dist/src-BPh-7A8j.mjs +7262 -0
- package/dist/{src-h6ZExh4A.mjs → src-pqi1HIGh.mjs} +1 -1
- package/dist/{text-input-dialog-Dvux6kIR.mjs → text-input-dialog-BIhpfWk_.mjs} +510 -40
- package/dist/{text-input-dialog-WSd537y1.mjs → text-input-dialog-CAaXBGxG.mjs} +1 -1
- package/package.json +107 -96
- package/dist/base64-js-DzVmk6Nb.mjs +0 -95
- package/dist/public/assets/index-CrkM1eFC.css +0 -1
- package/dist/public/assets/index-DYpA3Upa.js +0 -93
- package/dist/public/assets/index-DYpA3Upa.js.map +0 -1
- package/dist/public/assets/wasm-CG6Dc4jp.js +0 -2
- package/dist/public/assets/wasm-CG6Dc4jp.js.map +0 -1
- package/dist/src-tDEINaMV.mjs +0 -2249
|
@@ -4,7 +4,7 @@ import { dirname as __cjsShimDirname } from 'node:path';
|
|
|
4
4
|
const __filename = __cjsShimFileURLToPath(import.meta.url);
|
|
5
5
|
const __dirname = __cjsShimDirname(__filename);
|
|
6
6
|
import { a as __toCommonJS, i as __require, n as __esmMin, o as __toESM, r as __exportAll, t as __commonJSMin } from "./chunk-D90kvbyJ.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { n as require_base64_js, t as XMLParser } from "./XMLParser-DFAnGqkc.mjs";
|
|
8
8
|
import * as fs$1 from "node:fs/promises";
|
|
9
9
|
import * as path$1 from "node:path";
|
|
10
10
|
import { createRequire } from "module";
|
|
@@ -49723,8 +49723,9 @@ var import_lib = /* @__PURE__ */ __toESM(require_lib$1(), 1);
|
|
|
49723
49723
|
var import_turndown_cjs = /* @__PURE__ */ __toESM(require_turndown_cjs(), 1);
|
|
49724
49724
|
var import_turndown_plugin_gfm_cjs = require_turndown_plugin_gfm_cjs();
|
|
49725
49725
|
/**
|
|
49726
|
-
* Build a Turndown instance configured for GFM with the fixes
|
|
49727
|
-
* `~~strikethrough~~`, unescaped heading periods, and single-space list
|
|
49726
|
+
* Build a Turndown instance configured for GFM with the fixes this codebase
|
|
49727
|
+
* needs: `~~strikethrough~~`, unescaped heading periods, and single-space list
|
|
49728
|
+
* markers.
|
|
49728
49729
|
*
|
|
49729
49730
|
* Shared by the web scrapers (HTML → markdown) and the markit document engine
|
|
49730
49731
|
* (`src/markit`). The rule set must stay identical across both call sites.
|
|
@@ -49757,13 +49758,13 @@ function createTurndown() {
|
|
|
49757
49758
|
],
|
|
49758
49759
|
replacement(content, node) {
|
|
49759
49760
|
const level = Number(node.nodeName.charAt(1));
|
|
49760
|
-
return `\n\n${"#".repeat(level)} ${content.
|
|
49761
|
+
return `\n\n${"#".repeat(level)} ${content.replaceAll(/\\([.])/g, "$1").trim()}\n\n`;
|
|
49761
49762
|
}
|
|
49762
49763
|
});
|
|
49763
49764
|
turndown.addRule("listItem", {
|
|
49764
49765
|
filter: "li",
|
|
49765
49766
|
replacement(content, node, options) {
|
|
49766
|
-
const body = content.replace(/^\n+/, "").replace(/\n+$/, "\n").
|
|
49767
|
+
const body = content.replace(/^\n+/, "").replace(/\n+$/, "\n").replaceAll("\n", "\n ");
|
|
49767
49768
|
const parent = node.parentNode;
|
|
49768
49769
|
let prefix = `${options.bulletListMarker} `;
|
|
49769
49770
|
if (parent?.nodeName === "OL") {
|
|
@@ -49782,22 +49783,22 @@ function createTurndown() {
|
|
|
49782
49783
|
* - wrap the first row in `<thead>` when missing
|
|
49783
49784
|
*/
|
|
49784
49785
|
function normalizeTablesHtml(html) {
|
|
49785
|
-
let result = html.
|
|
49786
|
-
return `<${tag}${attrs}>${inner.replace(/^\s*<p>/i, "").replace(/<\/p>\s*$/i, "").
|
|
49786
|
+
let result = html.replaceAll(/<(td|th)([^>]*)>([\s\S]*?)<\/(td|th)>/gi, (_match, tag, attrs, inner, closeTag) => {
|
|
49787
|
+
return `<${tag}${attrs}>${inner.replace(/^\s*<p>/i, "").replace(/<\/p>\s*$/i, "").replaceAll(/<\/p>\s*<p>/gi, " ")}</${closeTag}>`;
|
|
49787
49788
|
});
|
|
49788
|
-
result = result.
|
|
49789
|
-
return `<table${attrs}><thead>${firstRow.
|
|
49789
|
+
result = result.replaceAll(/<table([^>]*)>\s*(?:<tbody>\s*)?(<tr[\s\S]*?<\/tr>)([\s\S]*?)<\/(?:tbody>\s*<\/)?table>/gi, (_match, attrs, firstRow, rest) => {
|
|
49790
|
+
return `<table${attrs}><thead>${firstRow.replaceAll("<td", "<th").replaceAll("</td>", "</th>")}</thead><tbody>${rest}</tbody></table>`;
|
|
49790
49791
|
});
|
|
49791
49792
|
return result;
|
|
49792
49793
|
}
|
|
49793
49794
|
//#endregion
|
|
49794
49795
|
//#region ../../packages/agent-core/src/markit/converters/docx.ts
|
|
49795
|
-
const EXTENSIONS$4 = [".docx"];
|
|
49796
|
+
const EXTENSIONS$4 = new Set([".docx"]);
|
|
49796
49797
|
const MIMETYPES$4 = ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"];
|
|
49797
49798
|
var DocxConverter = class {
|
|
49798
49799
|
name = "docx";
|
|
49799
49800
|
accepts(streamInfo) {
|
|
49800
|
-
if (streamInfo.extension && EXTENSIONS$4.
|
|
49801
|
+
if (streamInfo.extension && EXTENSIONS$4.has(streamInfo.extension)) return true;
|
|
49801
49802
|
if (streamInfo.mimetype && MIMETYPES$4.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
49802
49803
|
return false;
|
|
49803
49804
|
}
|
|
@@ -49828,3872 +49829,11 @@ var DocxConverter = class {
|
|
|
49828
49829
|
});
|
|
49829
49830
|
const { value: html } = await import_lib.convertToHtml({ buffer: input }, { convertImage });
|
|
49830
49831
|
let markdown = createTurndown().turndown(normalizeTablesHtml(html));
|
|
49831
|
-
if (!imageDir) markdown = markdown.
|
|
49832
|
+
if (!imageDir) markdown = markdown.replaceAll(/!\[([^\]]*)\]\(data:[^)]*\)/g, "<!-- image: $1 -->");
|
|
49832
49833
|
return { markdown: markdown.trim() };
|
|
49833
49834
|
}
|
|
49834
49835
|
};
|
|
49835
49836
|
//#endregion
|
|
49836
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/util.js
|
|
49837
|
-
const regexName = /* @__PURE__ */ new RegExp("^[:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$");
|
|
49838
|
-
function getAllMatches(string, regex) {
|
|
49839
|
-
const matches = [];
|
|
49840
|
-
let match = regex.exec(string);
|
|
49841
|
-
while (match) {
|
|
49842
|
-
const allmatches = [];
|
|
49843
|
-
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
49844
|
-
const len = match.length;
|
|
49845
|
-
for (let index = 0; index < len; index++) allmatches.push(match[index]);
|
|
49846
|
-
matches.push(allmatches);
|
|
49847
|
-
match = regex.exec(string);
|
|
49848
|
-
}
|
|
49849
|
-
return matches;
|
|
49850
|
-
}
|
|
49851
|
-
const isName = function(string) {
|
|
49852
|
-
const match = regexName.exec(string);
|
|
49853
|
-
return !(match === null || typeof match === "undefined");
|
|
49854
|
-
};
|
|
49855
|
-
function isExist(v) {
|
|
49856
|
-
return typeof v !== "undefined";
|
|
49857
|
-
}
|
|
49858
|
-
/**
|
|
49859
|
-
* Dangerous property names that could lead to prototype pollution or security issues
|
|
49860
|
-
*/
|
|
49861
|
-
const DANGEROUS_PROPERTY_NAMES = [
|
|
49862
|
-
"hasOwnProperty",
|
|
49863
|
-
"toString",
|
|
49864
|
-
"valueOf",
|
|
49865
|
-
"__defineGetter__",
|
|
49866
|
-
"__defineSetter__",
|
|
49867
|
-
"__lookupGetter__",
|
|
49868
|
-
"__lookupSetter__"
|
|
49869
|
-
];
|
|
49870
|
-
const criticalProperties = [
|
|
49871
|
-
"__proto__",
|
|
49872
|
-
"constructor",
|
|
49873
|
-
"prototype"
|
|
49874
|
-
];
|
|
49875
|
-
//#endregion
|
|
49876
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/validator.js
|
|
49877
|
-
const defaultOptions$1 = {
|
|
49878
|
-
allowBooleanAttributes: false,
|
|
49879
|
-
unpairedTags: []
|
|
49880
|
-
};
|
|
49881
|
-
function validate(xmlData, options) {
|
|
49882
|
-
options = Object.assign({}, defaultOptions$1, options);
|
|
49883
|
-
const tags = [];
|
|
49884
|
-
let tagFound = false;
|
|
49885
|
-
let reachedRoot = false;
|
|
49886
|
-
if (xmlData[0] === "") xmlData = xmlData.substr(1);
|
|
49887
|
-
for (let i = 0; i < xmlData.length; i++) if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
49888
|
-
i += 2;
|
|
49889
|
-
i = readPI(xmlData, i);
|
|
49890
|
-
if (i.err) return i;
|
|
49891
|
-
} else if (xmlData[i] === "<") {
|
|
49892
|
-
let tagStartPos = i;
|
|
49893
|
-
i++;
|
|
49894
|
-
if (xmlData[i] === "!") {
|
|
49895
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
49896
|
-
continue;
|
|
49897
|
-
} else {
|
|
49898
|
-
let closingTag = false;
|
|
49899
|
-
if (xmlData[i] === "/") {
|
|
49900
|
-
closingTag = true;
|
|
49901
|
-
i++;
|
|
49902
|
-
}
|
|
49903
|
-
let tagName = "";
|
|
49904
|
-
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) tagName += xmlData[i];
|
|
49905
|
-
tagName = tagName.trim();
|
|
49906
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
49907
|
-
tagName = tagName.substring(0, tagName.length - 1);
|
|
49908
|
-
i--;
|
|
49909
|
-
}
|
|
49910
|
-
if (!validateTagName(tagName)) {
|
|
49911
|
-
let msg;
|
|
49912
|
-
if (tagName.trim().length === 0) msg = "Invalid space after '<'.";
|
|
49913
|
-
else msg = "Tag '" + tagName + "' is an invalid name.";
|
|
49914
|
-
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
49915
|
-
}
|
|
49916
|
-
const result = readAttributeStr(xmlData, i);
|
|
49917
|
-
if (result === false) return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
49918
|
-
let attrStr = result.value;
|
|
49919
|
-
i = result.index;
|
|
49920
|
-
if (attrStr[attrStr.length - 1] === "/") {
|
|
49921
|
-
const attrStrStart = i - attrStr.length;
|
|
49922
|
-
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
49923
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
49924
|
-
if (isValid === true) tagFound = true;
|
|
49925
|
-
else return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
49926
|
-
} else if (closingTag) if (!result.tagClosed) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
49927
|
-
else if (attrStr.trim().length > 0) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
49928
|
-
else if (tags.length === 0) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
49929
|
-
else {
|
|
49930
|
-
const otg = tags.pop();
|
|
49931
|
-
if (tagName !== otg.tagName) {
|
|
49932
|
-
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
49933
|
-
return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
49934
|
-
}
|
|
49935
|
-
if (tags.length == 0) reachedRoot = true;
|
|
49936
|
-
}
|
|
49937
|
-
else {
|
|
49938
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
49939
|
-
if (isValid !== true) return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
49940
|
-
if (reachedRoot === true) return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
|
|
49941
|
-
else if (options.unpairedTags.indexOf(tagName) !== -1) {} else tags.push({
|
|
49942
|
-
tagName,
|
|
49943
|
-
tagStartPos
|
|
49944
|
-
});
|
|
49945
|
-
tagFound = true;
|
|
49946
|
-
}
|
|
49947
|
-
for (i++; i < xmlData.length; i++) if (xmlData[i] === "<") if (xmlData[i + 1] === "!") {
|
|
49948
|
-
i++;
|
|
49949
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
49950
|
-
continue;
|
|
49951
|
-
} else if (xmlData[i + 1] === "?") {
|
|
49952
|
-
i = readPI(xmlData, ++i);
|
|
49953
|
-
if (i.err) return i;
|
|
49954
|
-
} else break;
|
|
49955
|
-
else if (xmlData[i] === "&") {
|
|
49956
|
-
const afterAmp = validateAmpersand(xmlData, i);
|
|
49957
|
-
if (afterAmp == -1) return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
49958
|
-
i = afterAmp;
|
|
49959
|
-
} else if (reachedRoot === true && !isWhiteSpace(xmlData[i])) return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
49960
|
-
if (xmlData[i] === "<") i--;
|
|
49961
|
-
}
|
|
49962
|
-
} else {
|
|
49963
|
-
if (isWhiteSpace(xmlData[i])) continue;
|
|
49964
|
-
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
49965
|
-
}
|
|
49966
|
-
if (!tagFound) return getErrorObject("InvalidXml", "Start tag expected.", 1);
|
|
49967
|
-
else if (tags.length == 1) return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
49968
|
-
else if (tags.length > 0) return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", {
|
|
49969
|
-
line: 1,
|
|
49970
|
-
col: 1
|
|
49971
|
-
});
|
|
49972
|
-
return true;
|
|
49973
|
-
}
|
|
49974
|
-
function isWhiteSpace(char) {
|
|
49975
|
-
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
49976
|
-
}
|
|
49977
|
-
/**
|
|
49978
|
-
* Read Processing insstructions and skip
|
|
49979
|
-
* @param {*} xmlData
|
|
49980
|
-
* @param {*} i
|
|
49981
|
-
*/
|
|
49982
|
-
function readPI(xmlData, i) {
|
|
49983
|
-
const start = i;
|
|
49984
|
-
for (; i < xmlData.length; i++) if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
49985
|
-
const tagname = xmlData.substr(start, i - start);
|
|
49986
|
-
if (i > 5 && tagname === "xml") return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
49987
|
-
else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
49988
|
-
i++;
|
|
49989
|
-
break;
|
|
49990
|
-
} else continue;
|
|
49991
|
-
}
|
|
49992
|
-
return i;
|
|
49993
|
-
}
|
|
49994
|
-
function readCommentAndCDATA(xmlData, i) {
|
|
49995
|
-
if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
|
|
49996
|
-
for (i += 3; i < xmlData.length; i++) if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
|
|
49997
|
-
i += 2;
|
|
49998
|
-
break;
|
|
49999
|
-
}
|
|
50000
|
-
} else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
|
|
50001
|
-
let angleBracketsCount = 1;
|
|
50002
|
-
for (i += 8; i < xmlData.length; i++) if (xmlData[i] === "<") angleBracketsCount++;
|
|
50003
|
-
else if (xmlData[i] === ">") {
|
|
50004
|
-
angleBracketsCount--;
|
|
50005
|
-
if (angleBracketsCount === 0) break;
|
|
50006
|
-
}
|
|
50007
|
-
} else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
|
|
50008
|
-
for (i += 8; i < xmlData.length; i++) if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
|
|
50009
|
-
i += 2;
|
|
50010
|
-
break;
|
|
50011
|
-
}
|
|
50012
|
-
}
|
|
50013
|
-
return i;
|
|
50014
|
-
}
|
|
50015
|
-
const doubleQuote = "\"";
|
|
50016
|
-
const singleQuote = "'";
|
|
50017
|
-
/**
|
|
50018
|
-
* Keep reading xmlData until '<' is found outside the attribute value.
|
|
50019
|
-
* @param {string} xmlData
|
|
50020
|
-
* @param {number} i
|
|
50021
|
-
*/
|
|
50022
|
-
function readAttributeStr(xmlData, i) {
|
|
50023
|
-
let attrStr = "";
|
|
50024
|
-
let startChar = "";
|
|
50025
|
-
let tagClosed = false;
|
|
50026
|
-
for (; i < xmlData.length; i++) {
|
|
50027
|
-
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) if (startChar === "") startChar = xmlData[i];
|
|
50028
|
-
else if (startChar !== xmlData[i]) {} else startChar = "";
|
|
50029
|
-
else if (xmlData[i] === ">") {
|
|
50030
|
-
if (startChar === "") {
|
|
50031
|
-
tagClosed = true;
|
|
50032
|
-
break;
|
|
50033
|
-
}
|
|
50034
|
-
}
|
|
50035
|
-
attrStr += xmlData[i];
|
|
50036
|
-
}
|
|
50037
|
-
if (startChar !== "") return false;
|
|
50038
|
-
return {
|
|
50039
|
-
value: attrStr,
|
|
50040
|
-
index: i,
|
|
50041
|
-
tagClosed
|
|
50042
|
-
};
|
|
50043
|
-
}
|
|
50044
|
-
/**
|
|
50045
|
-
* Select all the attributes whether valid or invalid.
|
|
50046
|
-
*/
|
|
50047
|
-
const validAttrStrRegxp = /* @__PURE__ */ new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?", "g");
|
|
50048
|
-
function validateAttributeString(attrStr, options) {
|
|
50049
|
-
const matches = getAllMatches(attrStr, validAttrStrRegxp);
|
|
50050
|
-
const attrNames = {};
|
|
50051
|
-
for (let i = 0; i < matches.length; i++) {
|
|
50052
|
-
if (matches[i][1].length === 0) return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
|
|
50053
|
-
else if (matches[i][3] !== void 0 && matches[i][4] === void 0) return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
|
|
50054
|
-
else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
50055
|
-
const attrName = matches[i][2];
|
|
50056
|
-
if (!validateAttrName(attrName)) return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
50057
|
-
if (!Object.prototype.hasOwnProperty.call(attrNames, attrName)) attrNames[attrName] = 1;
|
|
50058
|
-
else return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
50059
|
-
}
|
|
50060
|
-
return true;
|
|
50061
|
-
}
|
|
50062
|
-
function validateNumberAmpersand(xmlData, i) {
|
|
50063
|
-
let re = /\d/;
|
|
50064
|
-
if (xmlData[i] === "x") {
|
|
50065
|
-
i++;
|
|
50066
|
-
re = /[\da-fA-F]/;
|
|
50067
|
-
}
|
|
50068
|
-
for (; i < xmlData.length; i++) {
|
|
50069
|
-
if (xmlData[i] === ";") return i;
|
|
50070
|
-
if (!xmlData[i].match(re)) break;
|
|
50071
|
-
}
|
|
50072
|
-
return -1;
|
|
50073
|
-
}
|
|
50074
|
-
function validateAmpersand(xmlData, i) {
|
|
50075
|
-
i++;
|
|
50076
|
-
if (xmlData[i] === ";") return -1;
|
|
50077
|
-
if (xmlData[i] === "#") {
|
|
50078
|
-
i++;
|
|
50079
|
-
return validateNumberAmpersand(xmlData, i);
|
|
50080
|
-
}
|
|
50081
|
-
let count = 0;
|
|
50082
|
-
for (; i < xmlData.length; i++, count++) {
|
|
50083
|
-
if (xmlData[i].match(/\w/) && count < 20) continue;
|
|
50084
|
-
if (xmlData[i] === ";") break;
|
|
50085
|
-
return -1;
|
|
50086
|
-
}
|
|
50087
|
-
return i;
|
|
50088
|
-
}
|
|
50089
|
-
function getErrorObject(code, message, lineNumber) {
|
|
50090
|
-
return { err: {
|
|
50091
|
-
code,
|
|
50092
|
-
msg: message,
|
|
50093
|
-
line: lineNumber.line || lineNumber,
|
|
50094
|
-
col: lineNumber.col
|
|
50095
|
-
} };
|
|
50096
|
-
}
|
|
50097
|
-
function validateAttrName(attrName) {
|
|
50098
|
-
return isName(attrName);
|
|
50099
|
-
}
|
|
50100
|
-
function validateTagName(tagname) {
|
|
50101
|
-
return isName(tagname);
|
|
50102
|
-
}
|
|
50103
|
-
function getLineNumberForPosition(xmlData, index) {
|
|
50104
|
-
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
50105
|
-
return {
|
|
50106
|
-
line: lines.length,
|
|
50107
|
-
col: lines[lines.length - 1].length + 1
|
|
50108
|
-
};
|
|
50109
|
-
}
|
|
50110
|
-
function getPositionFromMatch(match) {
|
|
50111
|
-
return match.startIndex + match[1].length;
|
|
50112
|
-
}
|
|
50113
|
-
//#endregion
|
|
50114
|
-
//#region ../../node_modules/.pnpm/@nodable+entities@3.0.0/node_modules/@nodable/entities/src/entities.js
|
|
50115
|
-
/**
|
|
50116
|
-
* Currency Symbols
|
|
50117
|
-
* @type {Record<string, string>}
|
|
50118
|
-
*/
|
|
50119
|
-
const CURRENCY = {
|
|
50120
|
-
cent: "¢",
|
|
50121
|
-
pound: "£",
|
|
50122
|
-
curren: "¤",
|
|
50123
|
-
yen: "¥",
|
|
50124
|
-
euro: "€",
|
|
50125
|
-
dollar: "$",
|
|
50126
|
-
fnof: "ƒ",
|
|
50127
|
-
inr: "₹",
|
|
50128
|
-
af: "؋",
|
|
50129
|
-
birr: "ብር",
|
|
50130
|
-
peso: "₱",
|
|
50131
|
-
rub: "₽",
|
|
50132
|
-
won: "₩",
|
|
50133
|
-
yuan: "¥",
|
|
50134
|
-
cedil: "¸"
|
|
50135
|
-
};
|
|
50136
|
-
const XML = {
|
|
50137
|
-
amp: "&",
|
|
50138
|
-
apos: "'",
|
|
50139
|
-
gt: ">",
|
|
50140
|
-
lt: "<",
|
|
50141
|
-
quot: "\""
|
|
50142
|
-
};
|
|
50143
|
-
const COMMON_HTML = {
|
|
50144
|
-
nbsp: "\xA0",
|
|
50145
|
-
copy: "©",
|
|
50146
|
-
reg: "®",
|
|
50147
|
-
trade: "™",
|
|
50148
|
-
mdash: "—",
|
|
50149
|
-
ndash: "–",
|
|
50150
|
-
hellip: "…",
|
|
50151
|
-
laquo: "«",
|
|
50152
|
-
raquo: "»",
|
|
50153
|
-
lsquo: "‘",
|
|
50154
|
-
rsquo: "’",
|
|
50155
|
-
ldquo: "“",
|
|
50156
|
-
rdquo: "”",
|
|
50157
|
-
bull: "•",
|
|
50158
|
-
para: "¶",
|
|
50159
|
-
sect: "§",
|
|
50160
|
-
deg: "°",
|
|
50161
|
-
frac12: "½",
|
|
50162
|
-
frac14: "¼",
|
|
50163
|
-
frac34: "¾"
|
|
50164
|
-
};
|
|
50165
|
-
//#endregion
|
|
50166
|
-
//#region ../../node_modules/.pnpm/@nodable+entities@3.0.0/node_modules/@nodable/entities/src/EntityDecoder.js
|
|
50167
|
-
/**
|
|
50168
|
-
* Action constants for `onExternalEntity` and `onInputEntity` hooks.
|
|
50169
|
-
*
|
|
50170
|
-
* Use these instead of raw strings to avoid typos:
|
|
50171
|
-
*
|
|
50172
|
-
* @example
|
|
50173
|
-
* import EntityDecoder, { ENTITY_ACTION } from './EntityDecoder.js';
|
|
50174
|
-
* const dec = new EntityDecoder({
|
|
50175
|
-
* onInputEntity: (name, value) => ENTITY_ACTION.BLOCK,
|
|
50176
|
-
* });
|
|
50177
|
-
*/
|
|
50178
|
-
const ENTITY_ACTION = Object.freeze({
|
|
50179
|
-
/** Resolve and expand the entity normally. */
|
|
50180
|
-
ALLOW: "allow",
|
|
50181
|
-
/** Silently skip this entity — it will not be registered. */
|
|
50182
|
-
BLOCK: "block",
|
|
50183
|
-
/** Throw an error, aborting entity registration entirely. */
|
|
50184
|
-
THROW: "throw"
|
|
50185
|
-
});
|
|
50186
|
-
const SPECIAL_CHARS = /* @__PURE__ */ new Set("!?\\\\/[]$%{}^&*()<>|+");
|
|
50187
|
-
/**
|
|
50188
|
-
* Validate that an entity name contains no dangerous characters.
|
|
50189
|
-
* @param {string} name
|
|
50190
|
-
* @returns {string} the name, unchanged
|
|
50191
|
-
* @throws {Error} on invalid characters
|
|
50192
|
-
*/
|
|
50193
|
-
function validateEntityName$1(name) {
|
|
50194
|
-
if (name[0] === "#") throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${name}"`);
|
|
50195
|
-
for (const ch of name) if (SPECIAL_CHARS.has(ch)) throw new Error(`[EntityReplacer] Invalid character '${ch}' in entity name: "${name}"`);
|
|
50196
|
-
return name;
|
|
50197
|
-
}
|
|
50198
|
-
/**
|
|
50199
|
-
* Merge one or more entity maps into a flat name→string map.
|
|
50200
|
-
* Accepts either:
|
|
50201
|
-
* - plain string values: { amp: '&' }
|
|
50202
|
-
* - legacy {regex,val} / {regx,val}: { lt: { regex: /.../, val: '<' } }
|
|
50203
|
-
*
|
|
50204
|
-
* Values containing '&' are skipped (recursive expansion risk).
|
|
50205
|
-
*
|
|
50206
|
-
* @param {...object} maps
|
|
50207
|
-
* @returns {Record<string, string>}
|
|
50208
|
-
*/
|
|
50209
|
-
function mergeEntityMaps(...maps) {
|
|
50210
|
-
const out = Object.create(null);
|
|
50211
|
-
for (const map of maps) {
|
|
50212
|
-
if (!map) continue;
|
|
50213
|
-
for (const key of Object.keys(map)) {
|
|
50214
|
-
const raw = map[key];
|
|
50215
|
-
if (typeof raw === "string") out[key] = raw;
|
|
50216
|
-
else if (raw && typeof raw === "object" && raw.val !== void 0) {
|
|
50217
|
-
const val = raw.val;
|
|
50218
|
-
if (typeof val === "string") out[key] = val;
|
|
50219
|
-
}
|
|
50220
|
-
}
|
|
50221
|
-
}
|
|
50222
|
-
return out;
|
|
50223
|
-
}
|
|
50224
|
-
const LIMIT_TIER_EXTERNAL = "external";
|
|
50225
|
-
const LIMIT_TIER_BASE = "base";
|
|
50226
|
-
const LIMIT_TIER_ALL = "all";
|
|
50227
|
-
/**
|
|
50228
|
-
* Resolve `applyLimitsTo` option into a normalised Set of tier strings.
|
|
50229
|
-
* Accepted values: 'external' | 'base' | 'all' | string[]
|
|
50230
|
-
* Default: 'external' (only untrusted injected entities are counted).
|
|
50231
|
-
* @param {string|string[]|undefined} raw
|
|
50232
|
-
* @returns {Set<string>}
|
|
50233
|
-
*/
|
|
50234
|
-
function parseLimitTiers(raw) {
|
|
50235
|
-
if (!raw || raw === LIMIT_TIER_EXTERNAL) return new Set([LIMIT_TIER_EXTERNAL]);
|
|
50236
|
-
if (raw === LIMIT_TIER_ALL) return new Set([LIMIT_TIER_ALL]);
|
|
50237
|
-
if (raw === LIMIT_TIER_BASE) return new Set([LIMIT_TIER_BASE]);
|
|
50238
|
-
if (Array.isArray(raw)) return new Set(raw);
|
|
50239
|
-
return new Set([LIMIT_TIER_EXTERNAL]);
|
|
50240
|
-
}
|
|
50241
|
-
const NCR_LEVEL = Object.freeze({
|
|
50242
|
-
allow: 0,
|
|
50243
|
-
leave: 1,
|
|
50244
|
-
remove: 2,
|
|
50245
|
-
throw: 3
|
|
50246
|
-
});
|
|
50247
|
-
const XML10_ALLOWED_C0 = new Set([
|
|
50248
|
-
9,
|
|
50249
|
-
10,
|
|
50250
|
-
13
|
|
50251
|
-
]);
|
|
50252
|
-
/**
|
|
50253
|
-
* Parse the `ncr` constructor option into flat, hot-path-friendly fields.
|
|
50254
|
-
* @param {object|undefined} ncr
|
|
50255
|
-
* @returns {{ xmlVersion: number, onLevel: number, nullLevel: number }}
|
|
50256
|
-
*/
|
|
50257
|
-
function parseNCRConfig(ncr) {
|
|
50258
|
-
if (!ncr) return {
|
|
50259
|
-
xmlVersion: 1,
|
|
50260
|
-
onLevel: NCR_LEVEL.allow,
|
|
50261
|
-
nullLevel: NCR_LEVEL.remove
|
|
50262
|
-
};
|
|
50263
|
-
const xmlVersion = ncr.xmlVersion === 1.1 ? 1.1 : 1;
|
|
50264
|
-
const onLevel = NCR_LEVEL[ncr.onNCR] ?? NCR_LEVEL.allow;
|
|
50265
|
-
const nullLevel = NCR_LEVEL[ncr.nullNCR] ?? NCR_LEVEL.remove;
|
|
50266
|
-
return {
|
|
50267
|
-
xmlVersion,
|
|
50268
|
-
onLevel,
|
|
50269
|
-
nullLevel: Math.max(nullLevel, NCR_LEVEL.remove)
|
|
50270
|
-
};
|
|
50271
|
-
}
|
|
50272
|
-
/**
|
|
50273
|
-
* Single-pass, zero-regex entity replacer for XML/HTML content.
|
|
50274
|
-
*
|
|
50275
|
-
* Algorithm: scan the string once for '&', read to ';', resolve via map
|
|
50276
|
-
* or direct codepoint conversion, build output chunks, join once at the end.
|
|
50277
|
-
*
|
|
50278
|
-
* Entity lookup priority (highest → lowest):
|
|
50279
|
-
* 1. input / runtime (DOCTYPE entities for current document)
|
|
50280
|
-
* 2. persistent external (survive across documents)
|
|
50281
|
-
* 3. base named map (DEFAULT_XML_ENTITIES + user-supplied namedEntities)
|
|
50282
|
-
*
|
|
50283
|
-
* Both input and external resolve as the 'external' tier for limit purposes.
|
|
50284
|
-
* Base map entities resolve as the 'base' tier.
|
|
50285
|
-
*
|
|
50286
|
-
* Numeric / hex references (&#NNN; / &#xHH;) are resolved directly via
|
|
50287
|
-
* String.fromCodePoint() — no map needed. They count as 'base' tier.
|
|
50288
|
-
*
|
|
50289
|
-
* @example
|
|
50290
|
-
* const replacer = new EntityReplacer({ namedEntities: COMMON_HTML });
|
|
50291
|
-
* replacer.setExternalEntities({ brand: 'Acme' });
|
|
50292
|
-
*
|
|
50293
|
-
* const instance = replacer.reset();
|
|
50294
|
-
* instance.addInputEntities({ version: '1.0' });
|
|
50295
|
-
* instance.encode('&brand; v&version; <'); // 'Acme v1.0 <'
|
|
50296
|
-
*/
|
|
50297
|
-
var EntityDecoder = class {
|
|
50298
|
-
/**
|
|
50299
|
-
* @param {object} [options]
|
|
50300
|
-
* @param {object|null} [options.namedEntities] — extra named entities merged into base map
|
|
50301
|
-
* @param {object} [options.limit] — security limits
|
|
50302
|
-
* @param {number} [options.limit.maxTotalExpansions=0] — 0 = unlimited
|
|
50303
|
-
* @param {number} [options.limit.maxExpandedLength=0] — 0 = unlimited
|
|
50304
|
-
* @param {'external'|'base'|'all'|string[]} [options.limit.applyLimitsTo='external']
|
|
50305
|
-
* Which entity tiers count against the security limits:
|
|
50306
|
-
* - 'external' (default) — only input/runtime + persistent external entities
|
|
50307
|
-
* - 'base' — only DEFAULT_XML_ENTITIES + namedEntities
|
|
50308
|
-
* - 'all' — every entity regardless of tier
|
|
50309
|
-
* - string[] — explicit combination, e.g. ['external', 'base']
|
|
50310
|
-
* @param {((resolved: string, original: string) => string)|null} [options.postCheck=null]
|
|
50311
|
-
* @param {string[]} [options.remove=[]] — entity names (e.g. ['nbsp', '#13']) to delete (replace with empty string)
|
|
50312
|
-
* @param {string[]} [options.leave=[]] — entity names to keep as literal (unchanged in output)
|
|
50313
|
-
* @param {object} [options.ncr] — Numeric Character Reference controls
|
|
50314
|
-
* @param {1.0|1.1} [options.ncr.xmlVersion=1.0]
|
|
50315
|
-
* XML version governing which codepoint ranges are restricted:
|
|
50316
|
-
* - 1.0 — C0 controls U+0001–U+001F (except U+0009/000A/000D) are prohibited
|
|
50317
|
-
* - 1.1 — C0 controls are allowed when written as NCRs; C1 (U+007F–U+009F) decoded as-is
|
|
50318
|
-
* @param {'allow'|'leave'|'remove'|'throw'} [options.ncr.onNCR='allow']
|
|
50319
|
-
* Base action for numeric references. Severity order: allow < leave < remove < throw.
|
|
50320
|
-
* For codepoint ranges that carry a minimum level (surrogates → remove, XML 1.0 C0 → remove),
|
|
50321
|
-
* the effective action is max(onNCR, rangeMinimum).
|
|
50322
|
-
* @param {'remove'|'throw'} [options.ncr.nullNCR='remove']
|
|
50323
|
-
* Action for U+0000 (null). 'allow' and 'leave' are clamped to 'remove' since null is never safe.
|
|
50324
|
-
* @param {((name: string, value: string) => 'allow'|'block'|'throw')|null} [options.onExternalEntity=null]
|
|
50325
|
-
* Hook called when an external entity is registered via `setExternalEntities()` or
|
|
50326
|
-
* `addExternalEntity()`. Return `ENTITY_ACTION.ALLOW` to accept the entity,
|
|
50327
|
-
* `ENTITY_ACTION.BLOCK` to silently skip it, or `ENTITY_ACTION.THROW` to abort with an error.
|
|
50328
|
-
* @param {((name: string, value: string) => 'allow'|'block'|'throw')|null} [options.onInputEntity=null]
|
|
50329
|
-
* Hook called when an input entity is registered via `addInputEntities()`. Return
|
|
50330
|
-
* `ENTITY_ACTION.ALLOW` to accept, `ENTITY_ACTION.BLOCK` to silently skip, or
|
|
50331
|
-
* `ENTITY_ACTION.THROW` to abort with an error.
|
|
50332
|
-
*/
|
|
50333
|
-
constructor(options = {}) {
|
|
50334
|
-
this._limit = options.limit || {};
|
|
50335
|
-
this._maxTotalExpansions = this._limit.maxTotalExpansions || 0;
|
|
50336
|
-
this._maxExpandedLength = this._limit.maxExpandedLength || 0;
|
|
50337
|
-
this._postCheck = typeof options.postCheck === "function" ? options.postCheck : (r) => r;
|
|
50338
|
-
this._limitTiers = parseLimitTiers(this._limit.applyLimitsTo ?? LIMIT_TIER_EXTERNAL);
|
|
50339
|
-
this._numericAllowed = options.numericAllowed ?? true;
|
|
50340
|
-
this._baseMap = mergeEntityMaps(XML, options.namedEntities || null);
|
|
50341
|
-
/** @type {Record<string, string>} */
|
|
50342
|
-
this._externalMap = Object.create(null);
|
|
50343
|
-
/** @type {Record<string, string>} */
|
|
50344
|
-
this._inputMap = Object.create(null);
|
|
50345
|
-
this._totalExpansions = 0;
|
|
50346
|
-
this._expandedLength = 0;
|
|
50347
|
-
/** @type {Set<string>} */
|
|
50348
|
-
this._removeSet = new Set(options.remove && Array.isArray(options.remove) ? options.remove : []);
|
|
50349
|
-
/** @type {Set<string>} */
|
|
50350
|
-
this._leaveSet = new Set(options.leave && Array.isArray(options.leave) ? options.leave : []);
|
|
50351
|
-
const ncrCfg = parseNCRConfig(options.ncr);
|
|
50352
|
-
this._ncrXmlVersion = ncrCfg.xmlVersion;
|
|
50353
|
-
this._ncrOnLevel = ncrCfg.onLevel;
|
|
50354
|
-
this._ncrNullLevel = ncrCfg.nullLevel;
|
|
50355
|
-
/** @type {((name: string, value: string) => 'allow'|'block'|'throw')|null} */
|
|
50356
|
-
this._onExternalEntity = typeof options.onExternalEntity === "function" ? options.onExternalEntity : null;
|
|
50357
|
-
/** @type {((name: string, value: string) => 'allow'|'block'|'throw')|null} */
|
|
50358
|
-
this._onInputEntity = typeof options.onInputEntity === "function" ? options.onInputEntity : null;
|
|
50359
|
-
}
|
|
50360
|
-
/**
|
|
50361
|
-
* Invoke a registration hook for a single entity name/value pair.
|
|
50362
|
-
* Returns true when the entity should be accepted, false when it should be
|
|
50363
|
-
* silently skipped (BLOCK), and throws when the hook returns THROW.
|
|
50364
|
-
*
|
|
50365
|
-
* @param {((name: string, value: string) => 'allow'|'block'|'throw')|null} hook
|
|
50366
|
-
* @param {string} name
|
|
50367
|
-
* @param {string} value
|
|
50368
|
-
* @param {string} context — used in error messages ('external' | 'input')
|
|
50369
|
-
* @returns {boolean} true = accept, false = skip
|
|
50370
|
-
*/
|
|
50371
|
-
_applyRegistrationHook(hook, name, value, context) {
|
|
50372
|
-
if (!hook) return true;
|
|
50373
|
-
const action = hook(name, value);
|
|
50374
|
-
if (action === ENTITY_ACTION.BLOCK) return false;
|
|
50375
|
-
if (action === ENTITY_ACTION.THROW) throw new Error(`[EntityDecoder] Registration of ${context} entity "&${name};" was rejected by hook`);
|
|
50376
|
-
return true;
|
|
50377
|
-
}
|
|
50378
|
-
/**
|
|
50379
|
-
* Replace the full set of persistent external entities.
|
|
50380
|
-
* All keys are validated — throws on invalid characters.
|
|
50381
|
-
* If `onExternalEntity` is set, it is called once per entry; entries that
|
|
50382
|
-
* return `ENTITY_ACTION.BLOCK` are silently omitted, `ENTITY_ACTION.THROW`
|
|
50383
|
-
* aborts the whole call.
|
|
50384
|
-
* @param {Record<string, string | { regex?: RegExp, val: string }>} map
|
|
50385
|
-
*/
|
|
50386
|
-
setExternalEntities(map) {
|
|
50387
|
-
if (map) for (const key of Object.keys(map)) validateEntityName$1(key);
|
|
50388
|
-
if (!this._onExternalEntity) {
|
|
50389
|
-
this._externalMap = mergeEntityMaps(map);
|
|
50390
|
-
return;
|
|
50391
|
-
}
|
|
50392
|
-
const flat = mergeEntityMaps(map);
|
|
50393
|
-
const filtered = Object.create(null);
|
|
50394
|
-
for (const [name, value] of Object.entries(flat)) if (this._applyRegistrationHook(this._onExternalEntity, name, value, "external")) filtered[name] = value;
|
|
50395
|
-
this._externalMap = filtered;
|
|
50396
|
-
}
|
|
50397
|
-
/**
|
|
50398
|
-
* Add a single persistent external entity.
|
|
50399
|
-
* If `onExternalEntity` is set it is called before the entity is stored;
|
|
50400
|
-
* `ENTITY_ACTION.BLOCK` silently skips storage, `ENTITY_ACTION.THROW` raises.
|
|
50401
|
-
* @param {string} key
|
|
50402
|
-
* @param {string} value
|
|
50403
|
-
*/
|
|
50404
|
-
addExternalEntity(key, value) {
|
|
50405
|
-
validateEntityName$1(key);
|
|
50406
|
-
if (typeof value === "string" && value.indexOf("&") === -1) {
|
|
50407
|
-
if (this._applyRegistrationHook(this._onExternalEntity, key, value, "external")) this._externalMap[key] = value;
|
|
50408
|
-
}
|
|
50409
|
-
}
|
|
50410
|
-
/**
|
|
50411
|
-
* Inject DOCTYPE entities for the current document.
|
|
50412
|
-
* Also resets per-document expansion counters.
|
|
50413
|
-
* If `onInputEntity` is set it is called once per entry; entries returning
|
|
50414
|
-
* `ENTITY_ACTION.BLOCK` are silently omitted, `ENTITY_ACTION.THROW` aborts.
|
|
50415
|
-
* @param {Record<string, string | { regx?: RegExp, regex?: RegExp, val: string }>} map
|
|
50416
|
-
*/
|
|
50417
|
-
addInputEntities(map) {
|
|
50418
|
-
this._totalExpansions = 0;
|
|
50419
|
-
this._expandedLength = 0;
|
|
50420
|
-
if (!this._onInputEntity) {
|
|
50421
|
-
this._inputMap = mergeEntityMaps(map);
|
|
50422
|
-
return;
|
|
50423
|
-
}
|
|
50424
|
-
const flat = mergeEntityMaps(map);
|
|
50425
|
-
const filtered = Object.create(null);
|
|
50426
|
-
for (const [name, value] of Object.entries(flat)) if (this._applyRegistrationHook(this._onInputEntity, name, value, "input")) filtered[name] = value;
|
|
50427
|
-
this._inputMap = filtered;
|
|
50428
|
-
}
|
|
50429
|
-
/**
|
|
50430
|
-
* Wipe input/runtime entities and reset counters.
|
|
50431
|
-
* Call this before processing each new document.
|
|
50432
|
-
* @returns {this}
|
|
50433
|
-
*/
|
|
50434
|
-
reset() {
|
|
50435
|
-
this._inputMap = Object.create(null);
|
|
50436
|
-
this._totalExpansions = 0;
|
|
50437
|
-
this._expandedLength = 0;
|
|
50438
|
-
return this;
|
|
50439
|
-
}
|
|
50440
|
-
/**
|
|
50441
|
-
* Update the XML version used for NCR classification.
|
|
50442
|
-
* Call this as soon as the document's `<?xml version="...">` declaration is parsed.
|
|
50443
|
-
* @param {1.0|1.1|number} version
|
|
50444
|
-
*/
|
|
50445
|
-
setXmlVersion(version) {
|
|
50446
|
-
this._ncrXmlVersion = version === 1.1 ? 1.1 : 1;
|
|
50447
|
-
}
|
|
50448
|
-
/**
|
|
50449
|
-
* Replace all entity references in `str` in a single pass.
|
|
50450
|
-
*
|
|
50451
|
-
* @param {string} str
|
|
50452
|
-
* @returns {string}
|
|
50453
|
-
*/
|
|
50454
|
-
decode(str) {
|
|
50455
|
-
if (typeof str !== "string" || str.length === 0) return str;
|
|
50456
|
-
if (str.indexOf("&") === -1) return str;
|
|
50457
|
-
const original = str;
|
|
50458
|
-
const chunks = [];
|
|
50459
|
-
const len = str.length;
|
|
50460
|
-
let last = 0;
|
|
50461
|
-
let i = 0;
|
|
50462
|
-
const limitExpansions = this._maxTotalExpansions > 0;
|
|
50463
|
-
const limitLength = this._maxExpandedLength > 0;
|
|
50464
|
-
const checkLimits = limitExpansions || limitLength;
|
|
50465
|
-
while (i < len) {
|
|
50466
|
-
if (str.charCodeAt(i) !== 38) {
|
|
50467
|
-
i++;
|
|
50468
|
-
continue;
|
|
50469
|
-
}
|
|
50470
|
-
let j = i + 1;
|
|
50471
|
-
while (j < len && str.charCodeAt(j) !== 59 && j - i <= 32) j++;
|
|
50472
|
-
if (j >= len || str.charCodeAt(j) !== 59) {
|
|
50473
|
-
i++;
|
|
50474
|
-
continue;
|
|
50475
|
-
}
|
|
50476
|
-
const token = str.slice(i + 1, j);
|
|
50477
|
-
if (token.length === 0) {
|
|
50478
|
-
i++;
|
|
50479
|
-
continue;
|
|
50480
|
-
}
|
|
50481
|
-
let replacement;
|
|
50482
|
-
let tier;
|
|
50483
|
-
if (this._removeSet.has(token)) {
|
|
50484
|
-
replacement = "";
|
|
50485
|
-
if (tier === void 0) tier = LIMIT_TIER_EXTERNAL;
|
|
50486
|
-
} else if (this._leaveSet.has(token)) {
|
|
50487
|
-
i++;
|
|
50488
|
-
continue;
|
|
50489
|
-
} else if (token.charCodeAt(0) === 35) {
|
|
50490
|
-
const ncrResult = this._resolveNCR(token);
|
|
50491
|
-
if (ncrResult === void 0) {
|
|
50492
|
-
i++;
|
|
50493
|
-
continue;
|
|
50494
|
-
}
|
|
50495
|
-
replacement = ncrResult;
|
|
50496
|
-
tier = LIMIT_TIER_BASE;
|
|
50497
|
-
} else {
|
|
50498
|
-
const resolved = this._resolveName(token);
|
|
50499
|
-
replacement = resolved?.value;
|
|
50500
|
-
tier = resolved?.tier;
|
|
50501
|
-
}
|
|
50502
|
-
if (replacement === void 0) {
|
|
50503
|
-
i++;
|
|
50504
|
-
continue;
|
|
50505
|
-
}
|
|
50506
|
-
if (i > last) chunks.push(str.slice(last, i));
|
|
50507
|
-
chunks.push(replacement);
|
|
50508
|
-
last = j + 1;
|
|
50509
|
-
i = last;
|
|
50510
|
-
if (checkLimits && this._tierCounts(tier)) {
|
|
50511
|
-
if (limitExpansions) {
|
|
50512
|
-
this._totalExpansions++;
|
|
50513
|
-
if (this._totalExpansions > this._maxTotalExpansions) throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);
|
|
50514
|
-
}
|
|
50515
|
-
if (limitLength) {
|
|
50516
|
-
const delta = replacement.length - (token.length + 2);
|
|
50517
|
-
if (delta > 0) {
|
|
50518
|
-
this._expandedLength += delta;
|
|
50519
|
-
if (this._expandedLength > this._maxExpandedLength) throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`);
|
|
50520
|
-
}
|
|
50521
|
-
}
|
|
50522
|
-
}
|
|
50523
|
-
}
|
|
50524
|
-
if (last < len) chunks.push(str.slice(last));
|
|
50525
|
-
const result = chunks.length === 0 ? str : chunks.join("");
|
|
50526
|
-
return this._postCheck(result, original);
|
|
50527
|
-
}
|
|
50528
|
-
/**
|
|
50529
|
-
* Returns true if a resolved entity of the given tier should count
|
|
50530
|
-
* against the expansion/length limits.
|
|
50531
|
-
* @param {string} tier — LIMIT_TIER_EXTERNAL | LIMIT_TIER_BASE
|
|
50532
|
-
* @returns {boolean}
|
|
50533
|
-
*/
|
|
50534
|
-
_tierCounts(tier) {
|
|
50535
|
-
if (this._limitTiers.has(LIMIT_TIER_ALL)) return true;
|
|
50536
|
-
return this._limitTiers.has(tier);
|
|
50537
|
-
}
|
|
50538
|
-
/**
|
|
50539
|
-
* Resolve a named entity token (without & and ;).
|
|
50540
|
-
* Priority: inputMap > externalMap > baseMap
|
|
50541
|
-
* Returns the resolved value tagged with its limit tier.
|
|
50542
|
-
*
|
|
50543
|
-
* @param {string} name
|
|
50544
|
-
* @returns {{ value: string, tier: string }|undefined}
|
|
50545
|
-
*/
|
|
50546
|
-
_resolveName(name) {
|
|
50547
|
-
if (name in this._inputMap) return {
|
|
50548
|
-
value: this._inputMap[name],
|
|
50549
|
-
tier: LIMIT_TIER_EXTERNAL
|
|
50550
|
-
};
|
|
50551
|
-
if (name in this._externalMap) return {
|
|
50552
|
-
value: this._externalMap[name],
|
|
50553
|
-
tier: LIMIT_TIER_EXTERNAL
|
|
50554
|
-
};
|
|
50555
|
-
if (name in this._baseMap) return {
|
|
50556
|
-
value: this._baseMap[name],
|
|
50557
|
-
tier: LIMIT_TIER_BASE
|
|
50558
|
-
};
|
|
50559
|
-
}
|
|
50560
|
-
/**
|
|
50561
|
-
* Classify a codepoint and return the minimum action level that must be applied.
|
|
50562
|
-
* Returns -1 when no minimum is imposed (normal allow path).
|
|
50563
|
-
*
|
|
50564
|
-
* Ranges checked (in priority order):
|
|
50565
|
-
* 1. U+0000 — null, governed by nullNCR (always ≥ remove)
|
|
50566
|
-
* 2. U+D800–U+DFFF — surrogates, always prohibited (min: remove)
|
|
50567
|
-
* 3. U+0001–U+001F \ {0x09,0x0A,0x0D} — XML 1.0 restricted C0 (min: remove)
|
|
50568
|
-
* (skipped in XML 1.1 — C0 controls are allowed when written as NCRs)
|
|
50569
|
-
*
|
|
50570
|
-
* @param {number} cp — codepoint
|
|
50571
|
-
* @returns {number} — minimum NCR_LEVEL value, or -1 for no restriction
|
|
50572
|
-
*/
|
|
50573
|
-
_classifyNCR(cp) {
|
|
50574
|
-
if (cp === 0) return this._ncrNullLevel;
|
|
50575
|
-
if (cp >= 55296 && cp <= 57343) return NCR_LEVEL.remove;
|
|
50576
|
-
if (this._ncrXmlVersion === 1) {
|
|
50577
|
-
if (cp >= 1 && cp <= 31 && !XML10_ALLOWED_C0.has(cp)) return NCR_LEVEL.remove;
|
|
50578
|
-
}
|
|
50579
|
-
return -1;
|
|
50580
|
-
}
|
|
50581
|
-
/**
|
|
50582
|
-
* Execute a resolved NCR action.
|
|
50583
|
-
*
|
|
50584
|
-
* @param {number} action — NCR_LEVEL value
|
|
50585
|
-
* @param {string} token — raw token (e.g. '#38') for error messages
|
|
50586
|
-
* @param {number} cp — codepoint, used only for error messages
|
|
50587
|
-
* @returns {string|undefined}
|
|
50588
|
-
* - decoded character string → 'allow'
|
|
50589
|
-
* - '' → 'remove'
|
|
50590
|
-
* - undefined → 'leave' (caller must skip past '&' only)
|
|
50591
|
-
* - throws Error → 'throw'
|
|
50592
|
-
*/
|
|
50593
|
-
_applyNCRAction(action, token, cp) {
|
|
50594
|
-
switch (action) {
|
|
50595
|
-
case NCR_LEVEL.allow: return String.fromCodePoint(cp);
|
|
50596
|
-
case NCR_LEVEL.remove: return "";
|
|
50597
|
-
case NCR_LEVEL.leave: return;
|
|
50598
|
-
case NCR_LEVEL.throw: throw new Error(`[EntityDecoder] Prohibited numeric character reference &${token}; (U+${cp.toString(16).toUpperCase().padStart(4, "0")})`);
|
|
50599
|
-
default: return String.fromCodePoint(cp);
|
|
50600
|
-
}
|
|
50601
|
-
}
|
|
50602
|
-
/**
|
|
50603
|
-
* Full NCR resolution pipeline for a numeric token.
|
|
50604
|
-
*
|
|
50605
|
-
* Steps:
|
|
50606
|
-
* 1. Parse the codepoint (decimal or hex).
|
|
50607
|
-
* 2. Validate the raw codepoint range (NaN, <0, >0x10FFFF).
|
|
50608
|
-
* 3. If numericAllowed is false and no minimum restriction applies → leave as-is.
|
|
50609
|
-
* 4. Classify the codepoint to find the minimum required action level.
|
|
50610
|
-
* 5. Resolve effective action = max(onNCR, minimum).
|
|
50611
|
-
* 6. Apply and return.
|
|
50612
|
-
*
|
|
50613
|
-
* @param {string} token — e.g. '#38', '#x26', '#X26'
|
|
50614
|
-
* @returns {string|undefined}
|
|
50615
|
-
* - string (incl. '') — replacement ('' = remove)
|
|
50616
|
-
* - undefined — leave original &token; as-is
|
|
50617
|
-
*/
|
|
50618
|
-
_resolveNCR(token) {
|
|
50619
|
-
const second = token.charCodeAt(1);
|
|
50620
|
-
let cp;
|
|
50621
|
-
if (second === 120 || second === 88) cp = parseInt(token.slice(2), 16);
|
|
50622
|
-
else cp = parseInt(token.slice(1), 10);
|
|
50623
|
-
if (Number.isNaN(cp) || cp < 0 || cp > 1114111) return void 0;
|
|
50624
|
-
const minimum = this._classifyNCR(cp);
|
|
50625
|
-
if (!this._numericAllowed && minimum < NCR_LEVEL.remove) return void 0;
|
|
50626
|
-
const effective = minimum === -1 ? this._ncrOnLevel : Math.max(this._ncrOnLevel, minimum);
|
|
50627
|
-
return this._applyNCRAction(effective, token, cp);
|
|
50628
|
-
}
|
|
50629
|
-
};
|
|
50630
|
-
//#endregion
|
|
50631
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
|
|
50632
|
-
const defaultOnDangerousProperty = (name) => {
|
|
50633
|
-
if (DANGEROUS_PROPERTY_NAMES.includes(name)) return "__" + name;
|
|
50634
|
-
return name;
|
|
50635
|
-
};
|
|
50636
|
-
const defaultOptions = {
|
|
50637
|
-
preserveOrder: false,
|
|
50638
|
-
attributeNamePrefix: "@_",
|
|
50639
|
-
attributesGroupName: false,
|
|
50640
|
-
textNodeName: "#text",
|
|
50641
|
-
ignoreAttributes: true,
|
|
50642
|
-
removeNSPrefix: false,
|
|
50643
|
-
allowBooleanAttributes: false,
|
|
50644
|
-
parseTagValue: true,
|
|
50645
|
-
parseAttributeValue: false,
|
|
50646
|
-
trimValues: true,
|
|
50647
|
-
cdataPropName: false,
|
|
50648
|
-
numberParseOptions: {
|
|
50649
|
-
hex: true,
|
|
50650
|
-
leadingZeros: true,
|
|
50651
|
-
eNotation: true,
|
|
50652
|
-
unicode: false
|
|
50653
|
-
},
|
|
50654
|
-
tagValueProcessor: function(tagName, val) {
|
|
50655
|
-
return val;
|
|
50656
|
-
},
|
|
50657
|
-
attributeValueProcessor: function(attrName, val) {
|
|
50658
|
-
return val;
|
|
50659
|
-
},
|
|
50660
|
-
stopNodes: [],
|
|
50661
|
-
alwaysCreateTextNode: false,
|
|
50662
|
-
isArray: () => false,
|
|
50663
|
-
commentPropName: false,
|
|
50664
|
-
unpairedTags: [],
|
|
50665
|
-
processEntities: true,
|
|
50666
|
-
htmlEntities: false,
|
|
50667
|
-
entityDecoder: null,
|
|
50668
|
-
ignoreDeclaration: false,
|
|
50669
|
-
ignorePiTags: false,
|
|
50670
|
-
transformTagName: false,
|
|
50671
|
-
transformAttributeName: false,
|
|
50672
|
-
updateTag: function(tagName, jPath, attrs) {
|
|
50673
|
-
return tagName;
|
|
50674
|
-
},
|
|
50675
|
-
captureMetaData: false,
|
|
50676
|
-
maxNestedTags: 100,
|
|
50677
|
-
strictReservedNames: true,
|
|
50678
|
-
jPath: true,
|
|
50679
|
-
onDangerousProperty: defaultOnDangerousProperty
|
|
50680
|
-
};
|
|
50681
|
-
/**
|
|
50682
|
-
* Validates that a property name is safe to use
|
|
50683
|
-
* @param {string} propertyName - The property name to validate
|
|
50684
|
-
* @param {string} optionName - The option field name (for error message)
|
|
50685
|
-
* @throws {Error} If property name is dangerous
|
|
50686
|
-
*/
|
|
50687
|
-
function validatePropertyName(propertyName, optionName) {
|
|
50688
|
-
if (typeof propertyName !== "string") return;
|
|
50689
|
-
const normalized = propertyName.toLowerCase();
|
|
50690
|
-
if (DANGEROUS_PROPERTY_NAMES.some((dangerous) => normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
50691
|
-
if (criticalProperties.some((dangerous) => normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
50692
|
-
}
|
|
50693
|
-
/**
|
|
50694
|
-
* Normalizes processEntities option for backward compatibility
|
|
50695
|
-
* @param {boolean|object} value
|
|
50696
|
-
* @returns {object} Always returns normalized object
|
|
50697
|
-
*/
|
|
50698
|
-
function normalizeProcessEntities(value, htmlEntities) {
|
|
50699
|
-
if (typeof value === "boolean") return {
|
|
50700
|
-
enabled: value,
|
|
50701
|
-
maxEntitySize: 1e4,
|
|
50702
|
-
maxExpansionDepth: 1e4,
|
|
50703
|
-
maxTotalExpansions: Infinity,
|
|
50704
|
-
maxExpandedLength: 1e5,
|
|
50705
|
-
maxEntityCount: 1e3,
|
|
50706
|
-
allowedTags: null,
|
|
50707
|
-
tagFilter: null,
|
|
50708
|
-
appliesTo: "all"
|
|
50709
|
-
};
|
|
50710
|
-
if (typeof value === "object" && value !== null) return {
|
|
50711
|
-
enabled: value.enabled !== false,
|
|
50712
|
-
maxEntitySize: Math.max(1, value.maxEntitySize ?? 1e4),
|
|
50713
|
-
maxExpansionDepth: Math.max(1, value.maxExpansionDepth ?? 1e4),
|
|
50714
|
-
maxTotalExpansions: Math.max(1, value.maxTotalExpansions ?? Infinity),
|
|
50715
|
-
maxExpandedLength: Math.max(1, value.maxExpandedLength ?? 1e5),
|
|
50716
|
-
maxEntityCount: Math.max(1, value.maxEntityCount ?? 1e3),
|
|
50717
|
-
allowedTags: value.allowedTags ?? null,
|
|
50718
|
-
tagFilter: value.tagFilter ?? null,
|
|
50719
|
-
appliesTo: value.appliesTo ?? "all"
|
|
50720
|
-
};
|
|
50721
|
-
return normalizeProcessEntities(true);
|
|
50722
|
-
}
|
|
50723
|
-
const buildOptions = function(options) {
|
|
50724
|
-
const built = Object.assign({}, defaultOptions, options);
|
|
50725
|
-
const propertyNameOptions = [
|
|
50726
|
-
{
|
|
50727
|
-
value: built.attributeNamePrefix,
|
|
50728
|
-
name: "attributeNamePrefix"
|
|
50729
|
-
},
|
|
50730
|
-
{
|
|
50731
|
-
value: built.attributesGroupName,
|
|
50732
|
-
name: "attributesGroupName"
|
|
50733
|
-
},
|
|
50734
|
-
{
|
|
50735
|
-
value: built.textNodeName,
|
|
50736
|
-
name: "textNodeName"
|
|
50737
|
-
},
|
|
50738
|
-
{
|
|
50739
|
-
value: built.cdataPropName,
|
|
50740
|
-
name: "cdataPropName"
|
|
50741
|
-
},
|
|
50742
|
-
{
|
|
50743
|
-
value: built.commentPropName,
|
|
50744
|
-
name: "commentPropName"
|
|
50745
|
-
}
|
|
50746
|
-
];
|
|
50747
|
-
for (const { value, name } of propertyNameOptions) if (value) validatePropertyName(value, name);
|
|
50748
|
-
if (built.onDangerousProperty === null) built.onDangerousProperty = defaultOnDangerousProperty;
|
|
50749
|
-
built.processEntities = normalizeProcessEntities(built.processEntities, built.htmlEntities);
|
|
50750
|
-
built.unpairedTagsSet = new Set(built.unpairedTags);
|
|
50751
|
-
if (built.stopNodes && Array.isArray(built.stopNodes)) built.stopNodes = built.stopNodes.map((node) => {
|
|
50752
|
-
if (typeof node === "string" && node.startsWith("*.")) return ".." + node.substring(2);
|
|
50753
|
-
return node;
|
|
50754
|
-
});
|
|
50755
|
-
return built;
|
|
50756
|
-
};
|
|
50757
|
-
//#endregion
|
|
50758
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
|
|
50759
|
-
let METADATA_SYMBOL$1;
|
|
50760
|
-
if (typeof Symbol !== "function") METADATA_SYMBOL$1 = "@@xmlMetadata";
|
|
50761
|
-
else METADATA_SYMBOL$1 = Symbol("XML Node Metadata");
|
|
50762
|
-
var XmlNode = class {
|
|
50763
|
-
constructor(tagname) {
|
|
50764
|
-
this.tagname = tagname;
|
|
50765
|
-
this.child = [];
|
|
50766
|
-
this[":@"] = Object.create(null);
|
|
50767
|
-
}
|
|
50768
|
-
add(key, val) {
|
|
50769
|
-
if (key === "__proto__") key = "#__proto__";
|
|
50770
|
-
this.child.push({ [key]: val });
|
|
50771
|
-
}
|
|
50772
|
-
addChild(node, startIndex) {
|
|
50773
|
-
if (node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
50774
|
-
if (node[":@"] && Object.keys(node[":@"]).length > 0) this.child.push({
|
|
50775
|
-
[node.tagname]: node.child,
|
|
50776
|
-
[":@"]: node[":@"]
|
|
50777
|
-
});
|
|
50778
|
-
else this.child.push({ [node.tagname]: node.child });
|
|
50779
|
-
if (startIndex !== void 0) this.child[this.child.length - 1][METADATA_SYMBOL$1] = { startIndex };
|
|
50780
|
-
}
|
|
50781
|
-
/** symbol used for metadata */
|
|
50782
|
-
static getMetaDataSymbol() {
|
|
50783
|
-
return METADATA_SYMBOL$1;
|
|
50784
|
-
}
|
|
50785
|
-
};
|
|
50786
|
-
//#endregion
|
|
50787
|
-
//#region ../../node_modules/.pnpm/xml-naming@0.3.0/node_modules/xml-naming/src/index.js
|
|
50788
|
-
/**
|
|
50789
|
-
* xml-naming
|
|
50790
|
-
* Validates XML Name productions as defined in the XML 1.0 and 1.1 specifications.
|
|
50791
|
-
* Covers: Name, NCName, QName, NMToken, NMTokens
|
|
50792
|
-
*
|
|
50793
|
-
* XML 1.0 spec: https://www.w3.org/TR/xml/#NT-Name
|
|
50794
|
-
* XML 1.1 spec: https://www.w3.org/TR/xml11/#NT-NameStartChar
|
|
50795
|
-
* XML NS spec: https://www.w3.org/TR/xml-names/#NT-NCName
|
|
50796
|
-
*/
|
|
50797
|
-
const nameStartChar10 = ":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�";
|
|
50798
|
-
const nameChar10 = ":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�\\-\\.\\d·̀-ͯ‿-⁀";
|
|
50799
|
-
const nameStartChar11 = ":A-Za-z_À-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�𐀀-";
|
|
50800
|
-
const nameChar11 = ":A-Za-z_À-˿Ͱ-ͽͿ-҆҈--⁰-Ⰰ-、-豈-﷏ﷰ-�𐀀-\\-\\.\\d·̀-ͯ҇‿-⁀";
|
|
50801
|
-
const buildRegexes = (startChar, char, flags = "") => {
|
|
50802
|
-
const ncNamePat = `[${startChar.replace(":", "")}][${char.replace(":", "")}]*`;
|
|
50803
|
-
return {
|
|
50804
|
-
name: new RegExp(`^[${startChar}][${char}]*$`, flags),
|
|
50805
|
-
ncName: new RegExp(`^${ncNamePat}$`, flags),
|
|
50806
|
-
qName: new RegExp(`^${ncNamePat}(?::${ncNamePat})?$`, flags),
|
|
50807
|
-
nmToken: new RegExp(`^[${char}]+$`, flags),
|
|
50808
|
-
nmTokens: new RegExp(`^[${char}]+(?:\\s+[${char}]+)*$`, flags)
|
|
50809
|
-
};
|
|
50810
|
-
};
|
|
50811
|
-
const regexes10 = buildRegexes(nameStartChar10, nameChar10);
|
|
50812
|
-
const regexes11 = buildRegexes(nameStartChar11, nameChar11, "u");
|
|
50813
|
-
const regexesAscii = buildRegexes(":A-Za-z_", ":A-Za-z_\\-\\.\\d");
|
|
50814
|
-
const getRegexes = (xmlVersion = "1.0", asciiOnly = false) => {
|
|
50815
|
-
if (asciiOnly) return regexesAscii;
|
|
50816
|
-
return xmlVersion === "1.1" ? regexes11 : regexes10;
|
|
50817
|
-
};
|
|
50818
|
-
/**
|
|
50819
|
-
* Returns true if the string is a valid QName (Qualified Name).
|
|
50820
|
-
* Allows exactly one colon as a prefix separator: prefix:localName.
|
|
50821
|
-
* Used for: element and attribute names in namespace-aware XML/SVG.
|
|
50822
|
-
*
|
|
50823
|
-
* @param {{ xmlVersion?: '1.0'|'1.1', asciiOnly?: boolean }} [opts]
|
|
50824
|
-
* asciiOnly: skip unicode-aware matching, ASCII names only (default false).
|
|
50825
|
-
*/
|
|
50826
|
-
const qName = (str, { xmlVersion = "1.0", asciiOnly = false } = {}) => getRegexes(xmlVersion, asciiOnly).qName.test(str);
|
|
50827
|
-
//#endregion
|
|
50828
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
|
|
50829
|
-
var DocTypeReader = class {
|
|
50830
|
-
constructor(options, xmlVersion) {
|
|
50831
|
-
this.suppressValidationErr = !options;
|
|
50832
|
-
this.options = options;
|
|
50833
|
-
this.xmlVersion = xmlVersion || 1;
|
|
50834
|
-
}
|
|
50835
|
-
setXmlVersion(xmlVersion = 1) {
|
|
50836
|
-
this.xmlVersion = xmlVersion;
|
|
50837
|
-
}
|
|
50838
|
-
readDocType(xmlData, i) {
|
|
50839
|
-
const entities = Object.create(null);
|
|
50840
|
-
let entityCount = 0;
|
|
50841
|
-
if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
|
|
50842
|
-
i = i + 9;
|
|
50843
|
-
let angleBracketsCount = 1;
|
|
50844
|
-
let hasBody = false, comment = false;
|
|
50845
|
-
let exp = "";
|
|
50846
|
-
for (; i < xmlData.length; i++) if (xmlData[i] === "<" && !comment) {
|
|
50847
|
-
if (hasBody && hasSeq(xmlData, "!ENTITY", i)) {
|
|
50848
|
-
i += 7;
|
|
50849
|
-
let entityName, val;
|
|
50850
|
-
[entityName, val, i] = this.readEntityExp(xmlData, i + 1, this.suppressValidationErr);
|
|
50851
|
-
if (val.indexOf("&") === -1) {
|
|
50852
|
-
if (this.options.enabled !== false && this.options.maxEntityCount != null && entityCount >= this.options.maxEntityCount) throw new Error(`Entity count (${entityCount + 1}) exceeds maximum allowed (${this.options.maxEntityCount})`);
|
|
50853
|
-
entities[entityName] = val;
|
|
50854
|
-
entityCount++;
|
|
50855
|
-
}
|
|
50856
|
-
} else if (hasBody && hasSeq(xmlData, "!ELEMENT", i)) {
|
|
50857
|
-
i += 8;
|
|
50858
|
-
const { index } = this.readElementExp(xmlData, i + 1);
|
|
50859
|
-
i = index;
|
|
50860
|
-
} else if (hasBody && hasSeq(xmlData, "!ATTLIST", i)) i += 8;
|
|
50861
|
-
else if (hasBody && hasSeq(xmlData, "!NOTATION", i)) {
|
|
50862
|
-
i += 9;
|
|
50863
|
-
const { index } = this.readNotationExp(xmlData, i + 1, this.suppressValidationErr);
|
|
50864
|
-
i = index;
|
|
50865
|
-
} else if (hasSeq(xmlData, "!--", i)) comment = true;
|
|
50866
|
-
else throw new Error(`Invalid DOCTYPE`);
|
|
50867
|
-
angleBracketsCount++;
|
|
50868
|
-
exp = "";
|
|
50869
|
-
} else if (xmlData[i] === ">") {
|
|
50870
|
-
if (comment) {
|
|
50871
|
-
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
|
|
50872
|
-
comment = false;
|
|
50873
|
-
angleBracketsCount--;
|
|
50874
|
-
}
|
|
50875
|
-
} else angleBracketsCount--;
|
|
50876
|
-
if (angleBracketsCount === 0) break;
|
|
50877
|
-
} else if (xmlData[i] === "[") hasBody = true;
|
|
50878
|
-
else exp += xmlData[i];
|
|
50879
|
-
if (angleBracketsCount !== 0) throw new Error(`Unclosed DOCTYPE`);
|
|
50880
|
-
} else throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
50881
|
-
return {
|
|
50882
|
-
entities,
|
|
50883
|
-
i
|
|
50884
|
-
};
|
|
50885
|
-
}
|
|
50886
|
-
readEntityExp(xmlData, i) {
|
|
50887
|
-
i = skipWhitespace(xmlData, i);
|
|
50888
|
-
const startIndex = i;
|
|
50889
|
-
while (i < xmlData.length && !/\s/.test(xmlData[i]) && xmlData[i] !== "\"" && xmlData[i] !== "'") i++;
|
|
50890
|
-
let entityName = xmlData.substring(startIndex, i);
|
|
50891
|
-
validateEntityName(entityName, { xmlVersion: this.xmlVersion });
|
|
50892
|
-
i = skipWhitespace(xmlData, i);
|
|
50893
|
-
if (!this.suppressValidationErr) {
|
|
50894
|
-
if (xmlData.substring(i, i + 6).toUpperCase() === "SYSTEM") throw new Error("External entities are not supported");
|
|
50895
|
-
else if (xmlData[i] === "%") throw new Error("Parameter entities are not supported");
|
|
50896
|
-
}
|
|
50897
|
-
let entityValue = "";
|
|
50898
|
-
[i, entityValue] = this.readIdentifierVal(xmlData, i, "entity");
|
|
50899
|
-
if (this.options.enabled !== false && this.options.maxEntitySize != null && entityValue.length > this.options.maxEntitySize) throw new Error(`Entity "${entityName}" size (${entityValue.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);
|
|
50900
|
-
i--;
|
|
50901
|
-
return [
|
|
50902
|
-
entityName,
|
|
50903
|
-
entityValue,
|
|
50904
|
-
i
|
|
50905
|
-
];
|
|
50906
|
-
}
|
|
50907
|
-
readNotationExp(xmlData, i) {
|
|
50908
|
-
i = skipWhitespace(xmlData, i);
|
|
50909
|
-
const startIndex = i;
|
|
50910
|
-
while (i < xmlData.length && !/\s/.test(xmlData[i])) i++;
|
|
50911
|
-
let notationName = xmlData.substring(startIndex, i);
|
|
50912
|
-
!this.suppressValidationErr && validateEntityName(notationName, { xmlVersion: this.xmlVersion });
|
|
50913
|
-
i = skipWhitespace(xmlData, i);
|
|
50914
|
-
const identifierType = xmlData.substring(i, i + 6).toUpperCase();
|
|
50915
|
-
if (!this.suppressValidationErr && identifierType !== "SYSTEM" && identifierType !== "PUBLIC") throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`);
|
|
50916
|
-
i += identifierType.length;
|
|
50917
|
-
i = skipWhitespace(xmlData, i);
|
|
50918
|
-
let publicIdentifier = null;
|
|
50919
|
-
let systemIdentifier = null;
|
|
50920
|
-
if (identifierType === "PUBLIC") {
|
|
50921
|
-
[i, publicIdentifier] = this.readIdentifierVal(xmlData, i, "publicIdentifier");
|
|
50922
|
-
i = skipWhitespace(xmlData, i);
|
|
50923
|
-
if (xmlData[i] === "\"" || xmlData[i] === "'") [i, systemIdentifier] = this.readIdentifierVal(xmlData, i, "systemIdentifier");
|
|
50924
|
-
} else if (identifierType === "SYSTEM") {
|
|
50925
|
-
[i, systemIdentifier] = this.readIdentifierVal(xmlData, i, "systemIdentifier");
|
|
50926
|
-
if (!this.suppressValidationErr && !systemIdentifier) throw new Error("Missing mandatory system identifier for SYSTEM notation");
|
|
50927
|
-
}
|
|
50928
|
-
return {
|
|
50929
|
-
notationName,
|
|
50930
|
-
publicIdentifier,
|
|
50931
|
-
systemIdentifier,
|
|
50932
|
-
index: --i
|
|
50933
|
-
};
|
|
50934
|
-
}
|
|
50935
|
-
readIdentifierVal(xmlData, i, type) {
|
|
50936
|
-
let identifierVal = "";
|
|
50937
|
-
const startChar = xmlData[i];
|
|
50938
|
-
if (startChar !== "\"" && startChar !== "'") throw new Error(`Expected quoted string, found "${startChar}"`);
|
|
50939
|
-
i++;
|
|
50940
|
-
const startIndex = i;
|
|
50941
|
-
while (i < xmlData.length && xmlData[i] !== startChar) i++;
|
|
50942
|
-
identifierVal = xmlData.substring(startIndex, i);
|
|
50943
|
-
if (xmlData[i] !== startChar) throw new Error(`Unterminated ${type} value`);
|
|
50944
|
-
i++;
|
|
50945
|
-
return [i, identifierVal];
|
|
50946
|
-
}
|
|
50947
|
-
readElementExp(xmlData, i) {
|
|
50948
|
-
i = skipWhitespace(xmlData, i);
|
|
50949
|
-
const startIndex = i;
|
|
50950
|
-
while (i < xmlData.length && !/\s/.test(xmlData[i])) i++;
|
|
50951
|
-
let elementName = xmlData.substring(startIndex, i);
|
|
50952
|
-
if (!this.suppressValidationErr && !qName(elementName, { xmlVersion: this.xmlVersion })) throw new Error(`Invalid element name: "${elementName}"`);
|
|
50953
|
-
i = skipWhitespace(xmlData, i);
|
|
50954
|
-
let contentModel = "";
|
|
50955
|
-
if (xmlData[i] === "E" && hasSeq(xmlData, "MPTY", i)) i += 4;
|
|
50956
|
-
else if (xmlData[i] === "A" && hasSeq(xmlData, "NY", i)) i += 2;
|
|
50957
|
-
else if (xmlData[i] === "(") {
|
|
50958
|
-
i++;
|
|
50959
|
-
const startIndex = i;
|
|
50960
|
-
while (i < xmlData.length && xmlData[i] !== ")") i++;
|
|
50961
|
-
contentModel = xmlData.substring(startIndex, i);
|
|
50962
|
-
if (xmlData[i] !== ")") throw new Error("Unterminated content model");
|
|
50963
|
-
} else if (!this.suppressValidationErr) throw new Error(`Invalid Element Expression, found "${xmlData[i]}"`);
|
|
50964
|
-
return {
|
|
50965
|
-
elementName,
|
|
50966
|
-
contentModel: contentModel.trim(),
|
|
50967
|
-
index: i
|
|
50968
|
-
};
|
|
50969
|
-
}
|
|
50970
|
-
readAttlistExp(xmlData, i) {
|
|
50971
|
-
i = skipWhitespace(xmlData, i);
|
|
50972
|
-
let startIndex = i;
|
|
50973
|
-
while (i < xmlData.length && !/\s/.test(xmlData[i])) i++;
|
|
50974
|
-
let elementName = xmlData.substring(startIndex, i);
|
|
50975
|
-
validateEntityName(elementName, { xmlVersion: this.xmlVersion });
|
|
50976
|
-
i = skipWhitespace(xmlData, i);
|
|
50977
|
-
startIndex = i;
|
|
50978
|
-
while (i < xmlData.length && !/\s/.test(xmlData[i])) i++;
|
|
50979
|
-
let attributeName = xmlData.substring(startIndex, i);
|
|
50980
|
-
if (!validateEntityName(attributeName, { xmlVersion: this.xmlVersion })) throw new Error(`Invalid attribute name: "${attributeName}"`);
|
|
50981
|
-
i = skipWhitespace(xmlData, i);
|
|
50982
|
-
let attributeType = "";
|
|
50983
|
-
if (xmlData.substring(i, i + 8).toUpperCase() === "NOTATION") {
|
|
50984
|
-
attributeType = "NOTATION";
|
|
50985
|
-
i += 8;
|
|
50986
|
-
i = skipWhitespace(xmlData, i);
|
|
50987
|
-
if (xmlData[i] !== "(") throw new Error(`Expected '(', found "${xmlData[i]}"`);
|
|
50988
|
-
i++;
|
|
50989
|
-
let allowedNotations = [];
|
|
50990
|
-
while (i < xmlData.length && xmlData[i] !== ")") {
|
|
50991
|
-
const startIndex = i;
|
|
50992
|
-
while (i < xmlData.length && xmlData[i] !== "|" && xmlData[i] !== ")") i++;
|
|
50993
|
-
let notation = xmlData.substring(startIndex, i);
|
|
50994
|
-
notation = notation.trim();
|
|
50995
|
-
if (!validateEntityName(notation, { xmlVersion: this.xmlVersion })) throw new Error(`Invalid notation name: "${notation}"`);
|
|
50996
|
-
allowedNotations.push(notation);
|
|
50997
|
-
if (xmlData[i] === "|") {
|
|
50998
|
-
i++;
|
|
50999
|
-
i = skipWhitespace(xmlData, i);
|
|
51000
|
-
}
|
|
51001
|
-
}
|
|
51002
|
-
if (xmlData[i] !== ")") throw new Error("Unterminated list of notations");
|
|
51003
|
-
i++;
|
|
51004
|
-
attributeType += " (" + allowedNotations.join("|") + ")";
|
|
51005
|
-
} else {
|
|
51006
|
-
const startIndex = i;
|
|
51007
|
-
while (i < xmlData.length && !/\s/.test(xmlData[i])) i++;
|
|
51008
|
-
attributeType += xmlData.substring(startIndex, i);
|
|
51009
|
-
if (!this.suppressValidationErr && ![
|
|
51010
|
-
"CDATA",
|
|
51011
|
-
"ID",
|
|
51012
|
-
"IDREF",
|
|
51013
|
-
"IDREFS",
|
|
51014
|
-
"ENTITY",
|
|
51015
|
-
"ENTITIES",
|
|
51016
|
-
"NMTOKEN",
|
|
51017
|
-
"NMTOKENS"
|
|
51018
|
-
].includes(attributeType.toUpperCase())) throw new Error(`Invalid attribute type: "${attributeType}"`);
|
|
51019
|
-
}
|
|
51020
|
-
i = skipWhitespace(xmlData, i);
|
|
51021
|
-
let defaultValue = "";
|
|
51022
|
-
if (xmlData.substring(i, i + 8).toUpperCase() === "#REQUIRED") {
|
|
51023
|
-
defaultValue = "#REQUIRED";
|
|
51024
|
-
i += 8;
|
|
51025
|
-
} else if (xmlData.substring(i, i + 7).toUpperCase() === "#IMPLIED") {
|
|
51026
|
-
defaultValue = "#IMPLIED";
|
|
51027
|
-
i += 7;
|
|
51028
|
-
} else [i, defaultValue] = this.readIdentifierVal(xmlData, i, "ATTLIST");
|
|
51029
|
-
return {
|
|
51030
|
-
elementName,
|
|
51031
|
-
attributeName,
|
|
51032
|
-
attributeType,
|
|
51033
|
-
defaultValue,
|
|
51034
|
-
index: i
|
|
51035
|
-
};
|
|
51036
|
-
}
|
|
51037
|
-
};
|
|
51038
|
-
const skipWhitespace = (data, index) => {
|
|
51039
|
-
while (index < data.length && /\s/.test(data[index])) index++;
|
|
51040
|
-
return index;
|
|
51041
|
-
};
|
|
51042
|
-
function hasSeq(data, seq, i) {
|
|
51043
|
-
for (let j = 0; j < seq.length; j++) if (seq[j] !== data[i + j + 1]) return false;
|
|
51044
|
-
return true;
|
|
51045
|
-
}
|
|
51046
|
-
function validateEntityName(name, xmlVersion) {
|
|
51047
|
-
if (qName(name, { xmlVersion })) return name;
|
|
51048
|
-
else throw new Error(`Invalid entity name ${name}`);
|
|
51049
|
-
}
|
|
51050
|
-
//#endregion
|
|
51051
|
-
//#region ../../node_modules/.pnpm/anynum@1.0.1/node_modules/anynum/digitTable.js
|
|
51052
|
-
/**
|
|
51053
|
-
* Flat lookup table: maps Unicode code point → ASCII digit (0-9).
|
|
51054
|
-
* Only decimal digit characters (Unicode category Nd) are included.
|
|
51055
|
-
*
|
|
51056
|
-
* Strategy: Int32Array of size (maxCodePoint - minCodePoint + 1).
|
|
51057
|
-
* Value 0xFF means "not a digit". Value 0-9 is the ASCII digit value.
|
|
51058
|
-
* This gives O(1) lookup with no branching, no bisect, no loop.
|
|
51059
|
-
*
|
|
51060
|
-
* Memory: range is 0x0660 to 0x1FBF0 → ~129,936 entries × 1 byte = ~127 KB.
|
|
51061
|
-
* Acceptable for a one-time init; lookup is a single array index.
|
|
51062
|
-
*/
|
|
51063
|
-
const SCRIPT_ZEROS = [
|
|
51064
|
-
48,
|
|
51065
|
-
1632,
|
|
51066
|
-
1776,
|
|
51067
|
-
2406,
|
|
51068
|
-
2534,
|
|
51069
|
-
2662,
|
|
51070
|
-
2790,
|
|
51071
|
-
2918,
|
|
51072
|
-
3046,
|
|
51073
|
-
3174,
|
|
51074
|
-
3302,
|
|
51075
|
-
3430,
|
|
51076
|
-
3558,
|
|
51077
|
-
3664,
|
|
51078
|
-
3792,
|
|
51079
|
-
3872,
|
|
51080
|
-
4160,
|
|
51081
|
-
4240,
|
|
51082
|
-
6112,
|
|
51083
|
-
6160,
|
|
51084
|
-
6470,
|
|
51085
|
-
6608,
|
|
51086
|
-
6784,
|
|
51087
|
-
6800,
|
|
51088
|
-
6992,
|
|
51089
|
-
7088,
|
|
51090
|
-
7232,
|
|
51091
|
-
7248,
|
|
51092
|
-
65296,
|
|
51093
|
-
120782,
|
|
51094
|
-
120792,
|
|
51095
|
-
120802,
|
|
51096
|
-
120812,
|
|
51097
|
-
120822,
|
|
51098
|
-
66720,
|
|
51099
|
-
68912,
|
|
51100
|
-
69734,
|
|
51101
|
-
69872,
|
|
51102
|
-
69942,
|
|
51103
|
-
70096,
|
|
51104
|
-
70384,
|
|
51105
|
-
70736,
|
|
51106
|
-
70864,
|
|
51107
|
-
71248,
|
|
51108
|
-
71360,
|
|
51109
|
-
71472,
|
|
51110
|
-
71904,
|
|
51111
|
-
72016,
|
|
51112
|
-
72688,
|
|
51113
|
-
72784,
|
|
51114
|
-
73040,
|
|
51115
|
-
73120,
|
|
51116
|
-
73552,
|
|
51117
|
-
92768,
|
|
51118
|
-
92864,
|
|
51119
|
-
93008,
|
|
51120
|
-
123200,
|
|
51121
|
-
123632,
|
|
51122
|
-
124144,
|
|
51123
|
-
125264,
|
|
51124
|
-
130032
|
|
51125
|
-
];
|
|
51126
|
-
const HIGH_MAP = /* @__PURE__ */ new Map();
|
|
51127
|
-
const LOW_MAX = 65535;
|
|
51128
|
-
const TABLE_OFFSET = 1632;
|
|
51129
|
-
const TABLE = new Uint8Array(63904).fill(255);
|
|
51130
|
-
for (const zero of SCRIPT_ZEROS) for (let d = 0; d < 10; d++) {
|
|
51131
|
-
const cp = zero + d;
|
|
51132
|
-
if (cp <= LOW_MAX) TABLE[cp - TABLE_OFFSET] = d;
|
|
51133
|
-
else HIGH_MAP.set(cp, d);
|
|
51134
|
-
}
|
|
51135
|
-
//#endregion
|
|
51136
|
-
//#region ../../node_modules/.pnpm/anynum@1.0.1/node_modules/anynum/anynum.js
|
|
51137
|
-
const CHAR_0 = 48;
|
|
51138
|
-
const CHAR_9 = 57;
|
|
51139
|
-
const CHAR_MINUS = 45;
|
|
51140
|
-
const MINUS_SET = new Set([
|
|
51141
|
-
8722,
|
|
51142
|
-
65293,
|
|
51143
|
-
65123
|
|
51144
|
-
]);
|
|
51145
|
-
/**
|
|
51146
|
-
* Normalize all Unicode decimal digit characters in a string to ASCII (0-9),
|
|
51147
|
-
* and normalize Unicode minus variants to ASCII '-' (U+002D).
|
|
51148
|
-
*
|
|
51149
|
-
* Non-digit, non-minus characters are passed through unchanged.
|
|
51150
|
-
*
|
|
51151
|
-
* Performance design:
|
|
51152
|
-
* - Fast path: if the string has no convertible characters, return it unchanged
|
|
51153
|
-
* (zero allocation).
|
|
51154
|
-
* - BMP digits (0x0660..0xFFFF excl. surrogates): flat Uint8Array lookup (O(1)).
|
|
51155
|
-
* - Supplementary plane digits (> 0xFFFF, encoded as surrogate pairs): Map lookup.
|
|
51156
|
-
* - Minus variants: checked inline with a small fixed Set.
|
|
51157
|
-
*
|
|
51158
|
-
* @param {string} str
|
|
51159
|
-
* @returns {string}
|
|
51160
|
-
*/
|
|
51161
|
-
function anynum(str) {
|
|
51162
|
-
if (typeof str !== "string") return str;
|
|
51163
|
-
const len = str.length;
|
|
51164
|
-
if (len === 0) return str;
|
|
51165
|
-
let firstHit = -1;
|
|
51166
|
-
for (let i = 0; i < len; i++) {
|
|
51167
|
-
const cc = str.charCodeAt(i);
|
|
51168
|
-
if (cc >= CHAR_0 && cc <= CHAR_9 || cc === CHAR_MINUS) continue;
|
|
51169
|
-
if (cc < 1632) {
|
|
51170
|
-
if (MINUS_SET.has(cc)) {
|
|
51171
|
-
firstHit = i;
|
|
51172
|
-
break;
|
|
51173
|
-
}
|
|
51174
|
-
continue;
|
|
51175
|
-
}
|
|
51176
|
-
if (cc >= 55296 && cc <= 56319) {
|
|
51177
|
-
if (i + 1 < len) {
|
|
51178
|
-
const low = str.charCodeAt(i + 1);
|
|
51179
|
-
if (low >= 56320 && low <= 57343) {
|
|
51180
|
-
const cp = 65536 + (cc - 55296 << 10) + (low - 56320);
|
|
51181
|
-
if (HIGH_MAP.has(cp)) {
|
|
51182
|
-
firstHit = i;
|
|
51183
|
-
break;
|
|
51184
|
-
}
|
|
51185
|
-
}
|
|
51186
|
-
}
|
|
51187
|
-
continue;
|
|
51188
|
-
}
|
|
51189
|
-
if (TABLE[cc - 1632] !== 255 || MINUS_SET.has(cc)) {
|
|
51190
|
-
firstHit = i;
|
|
51191
|
-
break;
|
|
51192
|
-
}
|
|
51193
|
-
}
|
|
51194
|
-
if (firstHit === -1) return str;
|
|
51195
|
-
const chars = [];
|
|
51196
|
-
if (firstHit > 0) chars.push(str.slice(0, firstHit));
|
|
51197
|
-
for (let i = firstHit; i < len; i++) {
|
|
51198
|
-
const cc = str.charCodeAt(i);
|
|
51199
|
-
if (cc >= CHAR_0 && cc <= CHAR_9 || cc === CHAR_MINUS) {
|
|
51200
|
-
chars.push(str[i]);
|
|
51201
|
-
continue;
|
|
51202
|
-
}
|
|
51203
|
-
if (cc < 1632) {
|
|
51204
|
-
chars.push(MINUS_SET.has(cc) ? "-" : str[i]);
|
|
51205
|
-
continue;
|
|
51206
|
-
}
|
|
51207
|
-
if (cc >= 55296 && cc <= 56319) {
|
|
51208
|
-
if (i + 1 < len) {
|
|
51209
|
-
const low = str.charCodeAt(i + 1);
|
|
51210
|
-
if (low >= 56320 && low <= 57343) {
|
|
51211
|
-
const cp = 65536 + (cc - 55296 << 10) + (low - 56320);
|
|
51212
|
-
const d = HIGH_MAP.get(cp);
|
|
51213
|
-
if (d !== void 0) {
|
|
51214
|
-
chars.push(String.fromCharCode(d + 48));
|
|
51215
|
-
i++;
|
|
51216
|
-
continue;
|
|
51217
|
-
}
|
|
51218
|
-
}
|
|
51219
|
-
}
|
|
51220
|
-
chars.push(str[i]);
|
|
51221
|
-
continue;
|
|
51222
|
-
}
|
|
51223
|
-
if (MINUS_SET.has(cc)) {
|
|
51224
|
-
chars.push("-");
|
|
51225
|
-
continue;
|
|
51226
|
-
}
|
|
51227
|
-
const d = TABLE[cc - TABLE_OFFSET];
|
|
51228
|
-
chars.push(d !== 255 ? String.fromCharCode(d + 48) : str[i]);
|
|
51229
|
-
}
|
|
51230
|
-
return chars.join("");
|
|
51231
|
-
}
|
|
51232
|
-
//#endregion
|
|
51233
|
-
//#region ../../node_modules/.pnpm/strnum@2.4.1/node_modules/strnum/strnum.js
|
|
51234
|
-
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
51235
|
-
const binRegex = /^0b[01]+$/;
|
|
51236
|
-
const octRegex = /^0o[0-7]+$/;
|
|
51237
|
-
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
|
|
51238
|
-
const consider = {
|
|
51239
|
-
hex: true,
|
|
51240
|
-
binary: false,
|
|
51241
|
-
octal: false,
|
|
51242
|
-
leadingZeros: true,
|
|
51243
|
-
decimalPoint: ".",
|
|
51244
|
-
eNotation: true,
|
|
51245
|
-
infinity: "original",
|
|
51246
|
-
unicode: false
|
|
51247
|
-
};
|
|
51248
|
-
function toNumber(str, options = {}) {
|
|
51249
|
-
options = Object.assign({}, consider, options);
|
|
51250
|
-
if (!str || typeof str !== "string") return str;
|
|
51251
|
-
let trimmedStr = str.trim();
|
|
51252
|
-
if (trimmedStr.length === 0) return str;
|
|
51253
|
-
else if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str;
|
|
51254
|
-
else if (trimmedStr === "0") return 0;
|
|
51255
|
-
if (options.unicode) {
|
|
51256
|
-
trimmedStr = anynum(trimmedStr);
|
|
51257
|
-
if (trimmedStr === "0") return 0;
|
|
51258
|
-
}
|
|
51259
|
-
if (options.hex && hexRegex.test(trimmedStr)) return parse_int(trimmedStr, 16);
|
|
51260
|
-
else if (options.binary && binRegex.test(trimmedStr)) return parse_int(trimmedStr, 2);
|
|
51261
|
-
else if (options.octal && octRegex.test(trimmedStr)) return parse_int(trimmedStr, 8);
|
|
51262
|
-
else if (!isFinite(trimmedStr)) return handleInfinity(str, Number(trimmedStr), options);
|
|
51263
|
-
else if (trimmedStr.includes("e") || trimmedStr.includes("E")) return resolveEnotation(str, trimmedStr, options);
|
|
51264
|
-
else {
|
|
51265
|
-
const match = numRegex.exec(trimmedStr);
|
|
51266
|
-
if (match) {
|
|
51267
|
-
const sign = match[1] || "";
|
|
51268
|
-
const leadingZeros = match[2];
|
|
51269
|
-
let numTrimmedByZeros = trimZeros(match[3]);
|
|
51270
|
-
const decimalAdjacentToLeadingZeros = sign ? str[leadingZeros.length + 1] === "." : str[leadingZeros.length] === ".";
|
|
51271
|
-
if (!options.leadingZeros && (leadingZeros.length > 1 || leadingZeros.length === 1 && !decimalAdjacentToLeadingZeros)) return str;
|
|
51272
|
-
else {
|
|
51273
|
-
const num = Number(trimmedStr);
|
|
51274
|
-
const parsedStr = String(num);
|
|
51275
|
-
if (num === 0) return num;
|
|
51276
|
-
if (parsedStr.search(/[eE]/) !== -1) if (options.eNotation) return num;
|
|
51277
|
-
else return str;
|
|
51278
|
-
else if (trimmedStr.indexOf(".") !== -1) if (parsedStr === "0") return num;
|
|
51279
|
-
else if (parsedStr === numTrimmedByZeros) return num;
|
|
51280
|
-
else if (parsedStr === `${sign}${numTrimmedByZeros}`) return num;
|
|
51281
|
-
else return str;
|
|
51282
|
-
let n = leadingZeros ? numTrimmedByZeros : trimmedStr;
|
|
51283
|
-
if (leadingZeros) return n === parsedStr || sign + n === parsedStr ? num : str;
|
|
51284
|
-
else return n === parsedStr || n === sign + parsedStr ? num : str;
|
|
51285
|
-
}
|
|
51286
|
-
} else return str;
|
|
51287
|
-
}
|
|
51288
|
-
}
|
|
51289
|
-
const eNotationRegx = /^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;
|
|
51290
|
-
function resolveEnotation(str, trimmedStr, options) {
|
|
51291
|
-
if (!options.eNotation) return str;
|
|
51292
|
-
const notation = trimmedStr.match(eNotationRegx);
|
|
51293
|
-
if (notation) {
|
|
51294
|
-
let sign = notation[1] || "";
|
|
51295
|
-
const eChar = notation[3].indexOf("e") === -1 ? "E" : "e";
|
|
51296
|
-
const leadingZeros = notation[2];
|
|
51297
|
-
const eAdjacentToLeadingZeros = sign ? str[leadingZeros.length + 1] === eChar : str[leadingZeros.length] === eChar;
|
|
51298
|
-
if (leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
|
|
51299
|
-
else if (leadingZeros.length === 1 && (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) return Number(trimmedStr);
|
|
51300
|
-
else if (leadingZeros.length > 0) if (options.leadingZeros && !eAdjacentToLeadingZeros) {
|
|
51301
|
-
trimmedStr = (notation[1] || "") + notation[3];
|
|
51302
|
-
return Number(trimmedStr);
|
|
51303
|
-
} else return str;
|
|
51304
|
-
else return Number(trimmedStr);
|
|
51305
|
-
} else return str;
|
|
51306
|
-
}
|
|
51307
|
-
/**
|
|
51308
|
-
*
|
|
51309
|
-
* @param {string} numStr without leading zeros
|
|
51310
|
-
* @returns
|
|
51311
|
-
*/
|
|
51312
|
-
function trimZeros(numStr) {
|
|
51313
|
-
if (numStr && numStr.indexOf(".") !== -1) {
|
|
51314
|
-
numStr = numStr.replace(/0+$/, "");
|
|
51315
|
-
if (numStr === ".") numStr = "0";
|
|
51316
|
-
else if (numStr[0] === ".") numStr = "0" + numStr;
|
|
51317
|
-
else if (numStr[numStr.length - 1] === ".") numStr = numStr.substring(0, numStr.length - 1);
|
|
51318
|
-
return numStr;
|
|
51319
|
-
}
|
|
51320
|
-
return numStr;
|
|
51321
|
-
}
|
|
51322
|
-
function parse_int(numStr, base) {
|
|
51323
|
-
const str = numStr.trim();
|
|
51324
|
-
if (base === 2 || base === 8) numStr = str.substring(2);
|
|
51325
|
-
if (parseInt) return parseInt(numStr, base);
|
|
51326
|
-
else if (Number.parseInt) return Number.parseInt(numStr, base);
|
|
51327
|
-
else if (window && window.parseInt) return window.parseInt(numStr, base);
|
|
51328
|
-
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported");
|
|
51329
|
-
}
|
|
51330
|
-
/**
|
|
51331
|
-
* Handle infinite values based on user option
|
|
51332
|
-
* @param {string} str - original input string
|
|
51333
|
-
* @param {number} num - parsed number (Infinity or -Infinity)
|
|
51334
|
-
* @param {object} options - user options
|
|
51335
|
-
* @returns {string|number|null} based on infinity option
|
|
51336
|
-
*/
|
|
51337
|
-
function handleInfinity(str, num, options) {
|
|
51338
|
-
const isPositive = num === Infinity;
|
|
51339
|
-
switch (options.infinity.toLowerCase()) {
|
|
51340
|
-
case "null": return null;
|
|
51341
|
-
case "infinity": return num;
|
|
51342
|
-
case "string": return isPositive ? "Infinity" : "-Infinity";
|
|
51343
|
-
default: return str;
|
|
51344
|
-
}
|
|
51345
|
-
}
|
|
51346
|
-
//#endregion
|
|
51347
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/ignoreAttributes.js
|
|
51348
|
-
function getIgnoreAttributesFn(ignoreAttributes) {
|
|
51349
|
-
if (typeof ignoreAttributes === "function") return ignoreAttributes;
|
|
51350
|
-
if (Array.isArray(ignoreAttributes)) return (attrName) => {
|
|
51351
|
-
for (const pattern of ignoreAttributes) {
|
|
51352
|
-
if (typeof pattern === "string" && attrName === pattern) return true;
|
|
51353
|
-
if (pattern instanceof RegExp && pattern.test(attrName)) return true;
|
|
51354
|
-
}
|
|
51355
|
-
};
|
|
51356
|
-
return () => false;
|
|
51357
|
-
}
|
|
51358
|
-
//#endregion
|
|
51359
|
-
//#region ../../node_modules/.pnpm/path-expression-matcher@1.6.2/node_modules/path-expression-matcher/src/Expression.js
|
|
51360
|
-
/**
|
|
51361
|
-
* Expression - Parses and stores a tag pattern expression
|
|
51362
|
-
*
|
|
51363
|
-
* Patterns are parsed once and stored in an optimized structure for fast matching.
|
|
51364
|
-
*
|
|
51365
|
-
* @example
|
|
51366
|
-
* const expr = new Expression("root.users.user");
|
|
51367
|
-
* const expr2 = new Expression("..user[id]:first");
|
|
51368
|
-
* const expr3 = new Expression("root/users/user", { separator: '/' });
|
|
51369
|
-
*/
|
|
51370
|
-
var Expression = class {
|
|
51371
|
-
/**
|
|
51372
|
-
* Create a new Expression
|
|
51373
|
-
* @param {string} pattern - Pattern string (e.g., "root.users.user", "..user[id]")
|
|
51374
|
-
* @param {Object} options - Configuration options
|
|
51375
|
-
* @param {string} options.separator - Path separator (default: '.')
|
|
51376
|
-
*/
|
|
51377
|
-
constructor(pattern, options = {}, data) {
|
|
51378
|
-
this.pattern = pattern;
|
|
51379
|
-
this.separator = options.separator || ".";
|
|
51380
|
-
this.segments = this._parse(pattern);
|
|
51381
|
-
this.data = data;
|
|
51382
|
-
this._hasDeepWildcard = this.segments.some((seg) => seg.type === "deep-wildcard");
|
|
51383
|
-
this._hasAttributeCondition = this.segments.some((seg) => seg.attrName !== void 0);
|
|
51384
|
-
this._hasPositionSelector = this.segments.some((seg) => seg.position !== void 0);
|
|
51385
|
-
}
|
|
51386
|
-
/**
|
|
51387
|
-
* Parse pattern string into segments
|
|
51388
|
-
* @private
|
|
51389
|
-
* @param {string} pattern - Pattern to parse
|
|
51390
|
-
* @returns {Array} Array of segment objects
|
|
51391
|
-
*/
|
|
51392
|
-
_parse(pattern) {
|
|
51393
|
-
const segments = [];
|
|
51394
|
-
let i = 0;
|
|
51395
|
-
let currentPart = "";
|
|
51396
|
-
while (i < pattern.length) if (pattern[i] === this.separator) if (i + 1 < pattern.length && pattern[i + 1] === this.separator) {
|
|
51397
|
-
if (currentPart.trim()) {
|
|
51398
|
-
segments.push(this._parseSegment(currentPart.trim()));
|
|
51399
|
-
currentPart = "";
|
|
51400
|
-
}
|
|
51401
|
-
segments.push({ type: "deep-wildcard" });
|
|
51402
|
-
i += 2;
|
|
51403
|
-
} else {
|
|
51404
|
-
if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
|
|
51405
|
-
currentPart = "";
|
|
51406
|
-
i++;
|
|
51407
|
-
}
|
|
51408
|
-
else {
|
|
51409
|
-
currentPart += pattern[i];
|
|
51410
|
-
i++;
|
|
51411
|
-
}
|
|
51412
|
-
if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
|
|
51413
|
-
return segments;
|
|
51414
|
-
}
|
|
51415
|
-
/**
|
|
51416
|
-
* Parse a single segment
|
|
51417
|
-
* @private
|
|
51418
|
-
* @param {string} part - Segment string (e.g., "user", "ns::user", "user[id]", "ns::user:first")
|
|
51419
|
-
* @returns {Object} Segment object
|
|
51420
|
-
*/
|
|
51421
|
-
_parseSegment(part) {
|
|
51422
|
-
const segment = { type: "tag" };
|
|
51423
|
-
let bracketContent = null;
|
|
51424
|
-
let withoutBrackets = part;
|
|
51425
|
-
const bracketMatch = part.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);
|
|
51426
|
-
if (bracketMatch) {
|
|
51427
|
-
withoutBrackets = bracketMatch[1] + bracketMatch[3];
|
|
51428
|
-
if (bracketMatch[2]) {
|
|
51429
|
-
const content = bracketMatch[2].slice(1, -1);
|
|
51430
|
-
if (content) bracketContent = content;
|
|
51431
|
-
}
|
|
51432
|
-
}
|
|
51433
|
-
let namespace = void 0;
|
|
51434
|
-
let tagAndPosition = withoutBrackets;
|
|
51435
|
-
if (withoutBrackets.includes("::")) {
|
|
51436
|
-
const nsIndex = withoutBrackets.indexOf("::");
|
|
51437
|
-
namespace = withoutBrackets.substring(0, nsIndex).trim();
|
|
51438
|
-
tagAndPosition = withoutBrackets.substring(nsIndex + 2).trim();
|
|
51439
|
-
if (!namespace) throw new Error(`Invalid namespace in pattern: ${part}`);
|
|
51440
|
-
}
|
|
51441
|
-
let tag = void 0;
|
|
51442
|
-
let positionMatch = null;
|
|
51443
|
-
if (tagAndPosition.includes(":")) {
|
|
51444
|
-
const colonIndex = tagAndPosition.lastIndexOf(":");
|
|
51445
|
-
const tagPart = tagAndPosition.substring(0, colonIndex).trim();
|
|
51446
|
-
const posPart = tagAndPosition.substring(colonIndex + 1).trim();
|
|
51447
|
-
if ([
|
|
51448
|
-
"first",
|
|
51449
|
-
"last",
|
|
51450
|
-
"odd",
|
|
51451
|
-
"even"
|
|
51452
|
-
].includes(posPart) || /^nth\(\d+\)$/.test(posPart)) {
|
|
51453
|
-
tag = tagPart;
|
|
51454
|
-
positionMatch = posPart;
|
|
51455
|
-
} else tag = tagAndPosition;
|
|
51456
|
-
} else tag = tagAndPosition;
|
|
51457
|
-
if (!tag) throw new Error(`Invalid segment pattern: ${part}`);
|
|
51458
|
-
segment.tag = tag;
|
|
51459
|
-
if (namespace) segment.namespace = namespace;
|
|
51460
|
-
if (bracketContent) if (bracketContent.includes("=")) {
|
|
51461
|
-
const eqIndex = bracketContent.indexOf("=");
|
|
51462
|
-
segment.attrName = bracketContent.substring(0, eqIndex).trim();
|
|
51463
|
-
segment.attrValue = bracketContent.substring(eqIndex + 1).trim();
|
|
51464
|
-
} else segment.attrName = bracketContent.trim();
|
|
51465
|
-
if (positionMatch) {
|
|
51466
|
-
const nthMatch = positionMatch.match(/^nth\((\d+)\)$/);
|
|
51467
|
-
if (nthMatch) {
|
|
51468
|
-
segment.position = "nth";
|
|
51469
|
-
segment.positionValue = parseInt(nthMatch[1], 10);
|
|
51470
|
-
} else segment.position = positionMatch;
|
|
51471
|
-
}
|
|
51472
|
-
return segment;
|
|
51473
|
-
}
|
|
51474
|
-
/**
|
|
51475
|
-
* Get the number of segments
|
|
51476
|
-
* @returns {number}
|
|
51477
|
-
*/
|
|
51478
|
-
get length() {
|
|
51479
|
-
return this.segments.length;
|
|
51480
|
-
}
|
|
51481
|
-
/**
|
|
51482
|
-
* Check if expression contains deep wildcard
|
|
51483
|
-
* @returns {boolean}
|
|
51484
|
-
*/
|
|
51485
|
-
hasDeepWildcard() {
|
|
51486
|
-
return this._hasDeepWildcard;
|
|
51487
|
-
}
|
|
51488
|
-
/**
|
|
51489
|
-
* Check if expression has attribute conditions
|
|
51490
|
-
* @returns {boolean}
|
|
51491
|
-
*/
|
|
51492
|
-
hasAttributeCondition() {
|
|
51493
|
-
return this._hasAttributeCondition;
|
|
51494
|
-
}
|
|
51495
|
-
/**
|
|
51496
|
-
* Check if expression has position selectors
|
|
51497
|
-
* @returns {boolean}
|
|
51498
|
-
*/
|
|
51499
|
-
hasPositionSelector() {
|
|
51500
|
-
return this._hasPositionSelector;
|
|
51501
|
-
}
|
|
51502
|
-
/**
|
|
51503
|
-
* Get string representation
|
|
51504
|
-
* @returns {string}
|
|
51505
|
-
*/
|
|
51506
|
-
toString() {
|
|
51507
|
-
return this.pattern;
|
|
51508
|
-
}
|
|
51509
|
-
};
|
|
51510
|
-
//#endregion
|
|
51511
|
-
//#region ../../node_modules/.pnpm/path-expression-matcher@1.6.2/node_modules/path-expression-matcher/src/ExpressionSet.js
|
|
51512
|
-
/**
|
|
51513
|
-
* ExpressionSet - An indexed collection of Expressions for efficient bulk matching
|
|
51514
|
-
*
|
|
51515
|
-
* Instead of iterating all expressions on every tag, ExpressionSet pre-indexes
|
|
51516
|
-
* them at insertion time by depth and terminal tag name. At match time, only
|
|
51517
|
-
* the relevant bucket is evaluated — typically reducing checks from O(E) to O(1)
|
|
51518
|
-
* lookup plus O(small bucket) matches.
|
|
51519
|
-
*
|
|
51520
|
-
* Three buckets are maintained:
|
|
51521
|
-
* - `_byDepthAndTag` — exact depth + exact tag name (tightest, used first)
|
|
51522
|
-
* - `_wildcardByDepth` — exact depth + wildcard tag `*` (depth-matched only)
|
|
51523
|
-
* - `_deepWildcards` — expressions containing `..` (cannot be depth-indexed)
|
|
51524
|
-
*
|
|
51525
|
-
* @example
|
|
51526
|
-
* import { Expression, ExpressionSet } from 'fast-xml-tagger';
|
|
51527
|
-
*
|
|
51528
|
-
* // Build once at config time
|
|
51529
|
-
* const stopNodes = new ExpressionSet();
|
|
51530
|
-
* stopNodes.add(new Expression('root.users.user'));
|
|
51531
|
-
* stopNodes.add(new Expression('root.config.setting'));
|
|
51532
|
-
* stopNodes.add(new Expression('..script'));
|
|
51533
|
-
*
|
|
51534
|
-
* // Query on every tag — hot path
|
|
51535
|
-
* if (stopNodes.matchesAny(matcher)) { ... }
|
|
51536
|
-
*/
|
|
51537
|
-
var ExpressionSet = class {
|
|
51538
|
-
constructor() {
|
|
51539
|
-
/** @type {Map<string, import('./Expression.js').default[]>} depth:tag → expressions */
|
|
51540
|
-
this._byDepthAndTag = /* @__PURE__ */ new Map();
|
|
51541
|
-
/** @type {Map<number, import('./Expression.js').default[]>} depth → wildcard-tag expressions */
|
|
51542
|
-
this._wildcardByDepth = /* @__PURE__ */ new Map();
|
|
51543
|
-
/** @type {import('./Expression.js').default[]} expressions containing deep wildcard (..) */
|
|
51544
|
-
this._deepWildcards = [];
|
|
51545
|
-
/** @type {Map<string, import('./Expression.js').default[]>} terminalTag → deep wildcard expressions */
|
|
51546
|
-
this._deepByTerminalTag = /* @__PURE__ */ new Map();
|
|
51547
|
-
/** @type {Set<string>} pattern strings already added — used for deduplication */
|
|
51548
|
-
this._patterns = /* @__PURE__ */ new Set();
|
|
51549
|
-
/** @type {boolean} whether the set is sealed against further additions */
|
|
51550
|
-
this._sealed = false;
|
|
51551
|
-
}
|
|
51552
|
-
/**
|
|
51553
|
-
* Add an Expression to the set.
|
|
51554
|
-
* Duplicate patterns (same pattern string) are silently ignored.
|
|
51555
|
-
*
|
|
51556
|
-
* @param {import('./Expression.js').default} expression - A pre-constructed Expression instance
|
|
51557
|
-
* @returns {this} for chaining
|
|
51558
|
-
* @throws {TypeError} if called after seal()
|
|
51559
|
-
*
|
|
51560
|
-
* @example
|
|
51561
|
-
* set.add(new Expression('root.users.user'));
|
|
51562
|
-
* set.add(new Expression('..script'));
|
|
51563
|
-
*/
|
|
51564
|
-
add(expression) {
|
|
51565
|
-
if (this._sealed) throw new TypeError("ExpressionSet is sealed. Create a new ExpressionSet to add more expressions.");
|
|
51566
|
-
if (this._patterns.has(expression.pattern)) return this;
|
|
51567
|
-
this._patterns.add(expression.pattern);
|
|
51568
|
-
if (expression.hasDeepWildcard()) {
|
|
51569
|
-
const lastSeg = expression.segments[expression.segments.length - 1];
|
|
51570
|
-
if (lastSeg && lastSeg.type !== "deep-wildcard" && lastSeg.tag !== "*") {
|
|
51571
|
-
const tag = lastSeg.tag;
|
|
51572
|
-
if (!this._deepByTerminalTag.has(tag)) this._deepByTerminalTag.set(tag, []);
|
|
51573
|
-
this._deepByTerminalTag.get(tag).push(expression);
|
|
51574
|
-
} else this._deepWildcards.push(expression);
|
|
51575
|
-
return this;
|
|
51576
|
-
}
|
|
51577
|
-
const depth = expression.length;
|
|
51578
|
-
const tag = expression.segments[expression.segments.length - 1]?.tag;
|
|
51579
|
-
if (!tag || tag === "*") {
|
|
51580
|
-
if (!this._wildcardByDepth.has(depth)) this._wildcardByDepth.set(depth, []);
|
|
51581
|
-
this._wildcardByDepth.get(depth).push(expression);
|
|
51582
|
-
} else {
|
|
51583
|
-
const key = `${depth}:${tag}`;
|
|
51584
|
-
if (!this._byDepthAndTag.has(key)) this._byDepthAndTag.set(key, []);
|
|
51585
|
-
this._byDepthAndTag.get(key).push(expression);
|
|
51586
|
-
}
|
|
51587
|
-
return this;
|
|
51588
|
-
}
|
|
51589
|
-
/**
|
|
51590
|
-
* Add multiple expressions at once.
|
|
51591
|
-
*
|
|
51592
|
-
* @param {import('./Expression.js').default[]} expressions - Array of Expression instances
|
|
51593
|
-
* @returns {this} for chaining
|
|
51594
|
-
*
|
|
51595
|
-
* @example
|
|
51596
|
-
* set.addAll([
|
|
51597
|
-
* new Expression('root.users.user'),
|
|
51598
|
-
* new Expression('root.config.setting'),
|
|
51599
|
-
* ]);
|
|
51600
|
-
*/
|
|
51601
|
-
addAll(expressions) {
|
|
51602
|
-
for (const expr of expressions) this.add(expr);
|
|
51603
|
-
return this;
|
|
51604
|
-
}
|
|
51605
|
-
/**
|
|
51606
|
-
* Check whether a pattern string is already present in the set.
|
|
51607
|
-
*
|
|
51608
|
-
* @param {import('./Expression.js').default} expression
|
|
51609
|
-
* @returns {boolean}
|
|
51610
|
-
*/
|
|
51611
|
-
has(expression) {
|
|
51612
|
-
return this._patterns.has(expression.pattern);
|
|
51613
|
-
}
|
|
51614
|
-
/**
|
|
51615
|
-
* Number of expressions in the set.
|
|
51616
|
-
* @type {number}
|
|
51617
|
-
*/
|
|
51618
|
-
get size() {
|
|
51619
|
-
return this._patterns.size;
|
|
51620
|
-
}
|
|
51621
|
-
/**
|
|
51622
|
-
* Seal the set against further modifications.
|
|
51623
|
-
* Useful to prevent accidental mutations after config is built.
|
|
51624
|
-
* Calling add() or addAll() on a sealed set throws a TypeError.
|
|
51625
|
-
*
|
|
51626
|
-
* @returns {this}
|
|
51627
|
-
*/
|
|
51628
|
-
seal() {
|
|
51629
|
-
this._sealed = true;
|
|
51630
|
-
return this;
|
|
51631
|
-
}
|
|
51632
|
-
/**
|
|
51633
|
-
* Whether the set has been sealed.
|
|
51634
|
-
* @type {boolean}
|
|
51635
|
-
*/
|
|
51636
|
-
get isSealed() {
|
|
51637
|
-
return this._sealed;
|
|
51638
|
-
}
|
|
51639
|
-
/**
|
|
51640
|
-
* Test whether the matcher's current path matches any expression in the set.
|
|
51641
|
-
*
|
|
51642
|
-
* Evaluation order (cheapest → most expensive):
|
|
51643
|
-
* 1. Exact depth + tag bucket — O(1) lookup, typically 0–2 expressions
|
|
51644
|
-
* 2. Depth-only wildcard bucket — O(1) lookup, rare
|
|
51645
|
-
* 3. Deep-wildcard list — always checked, but usually small
|
|
51646
|
-
*
|
|
51647
|
-
* @param {import('./Matcher.js').default} matcher - Matcher instance (or readOnly view)
|
|
51648
|
-
* @returns {boolean} true if any expression matches the current path
|
|
51649
|
-
*
|
|
51650
|
-
* @example
|
|
51651
|
-
* if (stopNodes.matchesAny(matcher)) {
|
|
51652
|
-
* // handle stop node
|
|
51653
|
-
* }
|
|
51654
|
-
*/
|
|
51655
|
-
matchesAny(matcher) {
|
|
51656
|
-
return this.findMatch(matcher) !== null;
|
|
51657
|
-
}
|
|
51658
|
-
/**
|
|
51659
|
-
* Find and return the first Expression that matches the matcher's current path.
|
|
51660
|
-
*
|
|
51661
|
-
* Uses the same evaluation order as matchesAny (cheapest → most expensive):
|
|
51662
|
-
* 1. Exact depth + tag bucket
|
|
51663
|
-
* 2. Depth-only wildcard bucket
|
|
51664
|
-
* 3. Deep-wildcard list
|
|
51665
|
-
*
|
|
51666
|
-
* @param {import('./Matcher.js').default} matcher - Matcher instance (or readOnly view)
|
|
51667
|
-
* @returns {import('./Expression.js').default | null} the first matching Expression, or null
|
|
51668
|
-
*
|
|
51669
|
-
* @example
|
|
51670
|
-
* const expr = stopNodes.findMatch(matcher);
|
|
51671
|
-
* if (expr) {
|
|
51672
|
-
* // access expr.config, expr.pattern, etc.
|
|
51673
|
-
* }
|
|
51674
|
-
*/
|
|
51675
|
-
findMatch(matcher) {
|
|
51676
|
-
const depth = matcher.getDepth();
|
|
51677
|
-
const tag = matcher.getCurrentTag();
|
|
51678
|
-
const exactKey = `${depth}:${tag}`;
|
|
51679
|
-
const exactBucket = this._byDepthAndTag.get(exactKey);
|
|
51680
|
-
if (exactBucket) {
|
|
51681
|
-
for (let i = 0; i < exactBucket.length; i++) if (matcher.matches(exactBucket[i])) return exactBucket[i];
|
|
51682
|
-
}
|
|
51683
|
-
const wildcardBucket = this._wildcardByDepth.get(depth);
|
|
51684
|
-
if (wildcardBucket) {
|
|
51685
|
-
for (let i = 0; i < wildcardBucket.length; i++) if (matcher.matches(wildcardBucket[i])) return wildcardBucket[i];
|
|
51686
|
-
}
|
|
51687
|
-
const deepBucket = this._deepByTerminalTag.get(tag);
|
|
51688
|
-
if (deepBucket) {
|
|
51689
|
-
for (let i = 0; i < deepBucket.length; i++) if (matcher.matches(deepBucket[i])) return deepBucket[i];
|
|
51690
|
-
}
|
|
51691
|
-
for (let i = 0; i < this._deepWildcards.length; i++) if (matcher.matches(this._deepWildcards[i])) return this._deepWildcards[i];
|
|
51692
|
-
return null;
|
|
51693
|
-
}
|
|
51694
|
-
};
|
|
51695
|
-
//#endregion
|
|
51696
|
-
//#region ../../node_modules/.pnpm/path-expression-matcher@1.6.2/node_modules/path-expression-matcher/src/Matcher.js
|
|
51697
|
-
/**
|
|
51698
|
-
* MatcherView - A lightweight read-only view over a Matcher's internal state.
|
|
51699
|
-
*
|
|
51700
|
-
* Created once by Matcher and reused across all callbacks. Holds a direct
|
|
51701
|
-
* reference to the parent Matcher so it always reflects current parser state
|
|
51702
|
-
* with zero copying or freezing overhead.
|
|
51703
|
-
*
|
|
51704
|
-
* Users receive this via {@link Matcher#readOnly} or directly from parser
|
|
51705
|
-
* callbacks. It exposes all query and matching methods but has no mutation
|
|
51706
|
-
* methods — misuse is caught at the TypeScript level rather than at runtime.
|
|
51707
|
-
*
|
|
51708
|
-
* @example
|
|
51709
|
-
* const matcher = new Matcher();
|
|
51710
|
-
* const view = matcher.readOnly();
|
|
51711
|
-
*
|
|
51712
|
-
* matcher.push("root", {});
|
|
51713
|
-
* view.getCurrentTag(); // "root"
|
|
51714
|
-
* view.getDepth(); // 1
|
|
51715
|
-
*/
|
|
51716
|
-
var MatcherView = class {
|
|
51717
|
-
/**
|
|
51718
|
-
* @param {Matcher} matcher - The parent Matcher instance to read from.
|
|
51719
|
-
*/
|
|
51720
|
-
constructor(matcher) {
|
|
51721
|
-
this._matcher = matcher;
|
|
51722
|
-
}
|
|
51723
|
-
/**
|
|
51724
|
-
* Get the path separator used by the parent matcher.
|
|
51725
|
-
* @returns {string}
|
|
51726
|
-
*/
|
|
51727
|
-
get separator() {
|
|
51728
|
-
return this._matcher.separator;
|
|
51729
|
-
}
|
|
51730
|
-
/**
|
|
51731
|
-
* Get current tag name.
|
|
51732
|
-
* @returns {string|undefined}
|
|
51733
|
-
*/
|
|
51734
|
-
getCurrentTag() {
|
|
51735
|
-
const path = this._matcher.path;
|
|
51736
|
-
return path.length > 0 ? path[path.length - 1].tag : void 0;
|
|
51737
|
-
}
|
|
51738
|
-
/**
|
|
51739
|
-
* Get current namespace.
|
|
51740
|
-
* @returns {string|undefined}
|
|
51741
|
-
*/
|
|
51742
|
-
getCurrentNamespace() {
|
|
51743
|
-
const path = this._matcher.path;
|
|
51744
|
-
return path.length > 0 ? path[path.length - 1].namespace : void 0;
|
|
51745
|
-
}
|
|
51746
|
-
/**
|
|
51747
|
-
* Get current node's attribute value.
|
|
51748
|
-
* @param {string} attrName
|
|
51749
|
-
* @returns {*}
|
|
51750
|
-
*/
|
|
51751
|
-
getAttrValue(attrName) {
|
|
51752
|
-
const path = this._matcher.path;
|
|
51753
|
-
if (path.length === 0) return void 0;
|
|
51754
|
-
return path[path.length - 1].values?.[attrName];
|
|
51755
|
-
}
|
|
51756
|
-
/**
|
|
51757
|
-
* Check if current node has an attribute.
|
|
51758
|
-
* @param {string} attrName
|
|
51759
|
-
* @returns {boolean}
|
|
51760
|
-
*/
|
|
51761
|
-
hasAttr(attrName) {
|
|
51762
|
-
const path = this._matcher.path;
|
|
51763
|
-
if (path.length === 0) return false;
|
|
51764
|
-
const current = path[path.length - 1];
|
|
51765
|
-
return current.values !== void 0 && attrName in current.values;
|
|
51766
|
-
}
|
|
51767
|
-
/**
|
|
51768
|
-
* Get the value of a "kept" attribute from the nearest ancestor (or
|
|
51769
|
-
* current node) that declared it via `push(tag, attrs, ns, { keep: [...] })`.
|
|
51770
|
-
* @param {string} attrName
|
|
51771
|
-
* @returns {*}
|
|
51772
|
-
*/
|
|
51773
|
-
getAnyParentAttr(attrName) {
|
|
51774
|
-
return this._matcher.getAnyParentAttr(attrName);
|
|
51775
|
-
}
|
|
51776
|
-
/**
|
|
51777
|
-
* Check whether any ancestor (or the current node) kept the given
|
|
51778
|
-
* attribute via `push(tag, attrs, ns, { keep: [...] })`.
|
|
51779
|
-
* @param {string} attrName
|
|
51780
|
-
* @returns {boolean}
|
|
51781
|
-
*/
|
|
51782
|
-
hasAnyParentAttr(attrName) {
|
|
51783
|
-
return this._matcher.hasAnyParentAttr(attrName);
|
|
51784
|
-
}
|
|
51785
|
-
/**
|
|
51786
|
-
* Get current node's sibling position (child index in parent).
|
|
51787
|
-
* @returns {number}
|
|
51788
|
-
*/
|
|
51789
|
-
getPosition() {
|
|
51790
|
-
const path = this._matcher.path;
|
|
51791
|
-
if (path.length === 0) return -1;
|
|
51792
|
-
return path[path.length - 1].position ?? 0;
|
|
51793
|
-
}
|
|
51794
|
-
/**
|
|
51795
|
-
* Get current node's repeat counter (occurrence count of this tag name).
|
|
51796
|
-
* @returns {number}
|
|
51797
|
-
*/
|
|
51798
|
-
getCounter() {
|
|
51799
|
-
const path = this._matcher.path;
|
|
51800
|
-
if (path.length === 0) return -1;
|
|
51801
|
-
return path[path.length - 1].counter ?? 0;
|
|
51802
|
-
}
|
|
51803
|
-
/**
|
|
51804
|
-
* Get current node's sibling index (alias for getPosition).
|
|
51805
|
-
* @returns {number}
|
|
51806
|
-
* @deprecated Use getPosition() or getCounter() instead
|
|
51807
|
-
*/
|
|
51808
|
-
getIndex() {
|
|
51809
|
-
return this.getPosition();
|
|
51810
|
-
}
|
|
51811
|
-
/**
|
|
51812
|
-
* Get current path depth.
|
|
51813
|
-
* @returns {number}
|
|
51814
|
-
*/
|
|
51815
|
-
getDepth() {
|
|
51816
|
-
return this._matcher.path.length;
|
|
51817
|
-
}
|
|
51818
|
-
/**
|
|
51819
|
-
* Get path as string.
|
|
51820
|
-
* @param {string} [separator] - Optional separator (uses default if not provided)
|
|
51821
|
-
* @param {boolean} [includeNamespace=true]
|
|
51822
|
-
* @returns {string}
|
|
51823
|
-
*/
|
|
51824
|
-
toString(separator, includeNamespace = true) {
|
|
51825
|
-
return this._matcher.toString(separator, includeNamespace);
|
|
51826
|
-
}
|
|
51827
|
-
/**
|
|
51828
|
-
* Get path as array of tag names.
|
|
51829
|
-
* @returns {string[]}
|
|
51830
|
-
*/
|
|
51831
|
-
toArray() {
|
|
51832
|
-
return this._matcher.path.map((n) => n.tag);
|
|
51833
|
-
}
|
|
51834
|
-
/**
|
|
51835
|
-
* Match current path against an Expression.
|
|
51836
|
-
* @param {Expression} expression
|
|
51837
|
-
* @returns {boolean}
|
|
51838
|
-
*/
|
|
51839
|
-
matches(expression) {
|
|
51840
|
-
return this._matcher.matches(expression);
|
|
51841
|
-
}
|
|
51842
|
-
/**
|
|
51843
|
-
* Match any expression in the given set against the current path.
|
|
51844
|
-
* @param {ExpressionSet} exprSet
|
|
51845
|
-
* @returns {boolean}
|
|
51846
|
-
*/
|
|
51847
|
-
matchesAny(exprSet) {
|
|
51848
|
-
return exprSet.matchesAny(this._matcher);
|
|
51849
|
-
}
|
|
51850
|
-
};
|
|
51851
|
-
/**
|
|
51852
|
-
* Matcher - Tracks current path in XML/JSON tree and matches against Expressions.
|
|
51853
|
-
*
|
|
51854
|
-
* The matcher maintains a stack of nodes representing the current path from root to
|
|
51855
|
-
* current tag. It only stores attribute values for the current (top) node to minimize
|
|
51856
|
-
* memory usage. Sibling tracking is used to auto-calculate position and counter.
|
|
51857
|
-
*
|
|
51858
|
-
* Use {@link Matcher#readOnly} to obtain a {@link MatcherView} safe to pass to
|
|
51859
|
-
* user callbacks — it always reflects current state with no Proxy overhead.
|
|
51860
|
-
*
|
|
51861
|
-
* @example
|
|
51862
|
-
* const matcher = new Matcher();
|
|
51863
|
-
* matcher.push("root", {});
|
|
51864
|
-
* matcher.push("users", {});
|
|
51865
|
-
* matcher.push("user", { id: "123", type: "admin" });
|
|
51866
|
-
*
|
|
51867
|
-
* const expr = new Expression("root.users.user");
|
|
51868
|
-
* matcher.matches(expr); // true
|
|
51869
|
-
*/
|
|
51870
|
-
var Matcher = class {
|
|
51871
|
-
/**
|
|
51872
|
-
* Create a new Matcher.
|
|
51873
|
-
* @param {Object} [options={}]
|
|
51874
|
-
* @param {string} [options.separator='.'] - Default path separator
|
|
51875
|
-
*/
|
|
51876
|
-
constructor(options = {}) {
|
|
51877
|
-
this.separator = options.separator || ".";
|
|
51878
|
-
this.path = [];
|
|
51879
|
-
this.siblingStacks = [];
|
|
51880
|
-
this._pathStringCache = null;
|
|
51881
|
-
this._view = new MatcherView(this);
|
|
51882
|
-
this._keptAttrs = [];
|
|
51883
|
-
}
|
|
51884
|
-
/**
|
|
51885
|
-
* Push a new tag onto the path.
|
|
51886
|
-
* @param {string} tagName
|
|
51887
|
-
* @param {Object|null} [attrValues=null]
|
|
51888
|
-
* @param {string|null} [namespace=null]
|
|
51889
|
-
* @param {Object|null} [options=null]
|
|
51890
|
-
* @param {string[]} [options.keep] - Names of attributes (from attrValues)
|
|
51891
|
-
*/
|
|
51892
|
-
push(tagName, attrValues = null, namespace = null, options = null) {
|
|
51893
|
-
this._pathStringCache = null;
|
|
51894
|
-
if (this.path.length > 0) this.path[this.path.length - 1].values = void 0;
|
|
51895
|
-
const currentLevel = this.path.length;
|
|
51896
|
-
let level = this.siblingStacks[currentLevel];
|
|
51897
|
-
if (!level) {
|
|
51898
|
-
level = {
|
|
51899
|
-
counts: /* @__PURE__ */ new Map(),
|
|
51900
|
-
total: 0
|
|
51901
|
-
};
|
|
51902
|
-
this.siblingStacks[currentLevel] = level;
|
|
51903
|
-
}
|
|
51904
|
-
const siblingKey = namespace ? `${namespace}:${tagName}` : tagName;
|
|
51905
|
-
const counter = level.counts.get(siblingKey) || 0;
|
|
51906
|
-
const position = level.total;
|
|
51907
|
-
level.counts.set(siblingKey, counter + 1);
|
|
51908
|
-
level.total++;
|
|
51909
|
-
const node = {
|
|
51910
|
-
tag: tagName,
|
|
51911
|
-
position,
|
|
51912
|
-
counter
|
|
51913
|
-
};
|
|
51914
|
-
if (namespace !== null && namespace !== void 0) node.namespace = namespace;
|
|
51915
|
-
if (attrValues !== null && attrValues !== void 0) node.values = attrValues;
|
|
51916
|
-
this.path.push(node);
|
|
51917
|
-
const depth = this.path.length;
|
|
51918
|
-
const keep = options !== null ? options.keep : null;
|
|
51919
|
-
if (keep !== null && keep !== void 0 && keep.length > 0 && attrValues) for (let i = 0; i < keep.length; i++) {
|
|
51920
|
-
const name = keep[i];
|
|
51921
|
-
if (attrValues[name] !== void 0) this._keptAttrs.push({
|
|
51922
|
-
depth,
|
|
51923
|
-
name,
|
|
51924
|
-
value: attrValues[name]
|
|
51925
|
-
});
|
|
51926
|
-
}
|
|
51927
|
-
}
|
|
51928
|
-
/**
|
|
51929
|
-
* Pop the last tag from the path.
|
|
51930
|
-
* @returns {Object|undefined} The popped node
|
|
51931
|
-
*/
|
|
51932
|
-
pop() {
|
|
51933
|
-
if (this.path.length === 0) return void 0;
|
|
51934
|
-
this._pathStringCache = null;
|
|
51935
|
-
const node = this.path.pop();
|
|
51936
|
-
if (this.siblingStacks.length > this.path.length + 1) this.siblingStacks.length = this.path.length + 1;
|
|
51937
|
-
const poppedDepth = this.path.length + 1;
|
|
51938
|
-
while (this._keptAttrs.length > 0 && this._keptAttrs[this._keptAttrs.length - 1].depth >= poppedDepth) this._keptAttrs.pop();
|
|
51939
|
-
return node;
|
|
51940
|
-
}
|
|
51941
|
-
/**
|
|
51942
|
-
* Update current node's attribute values.
|
|
51943
|
-
* Useful when attributes are parsed after push.
|
|
51944
|
-
* @param {Object} attrValues
|
|
51945
|
-
*/
|
|
51946
|
-
updateCurrent(attrValues) {
|
|
51947
|
-
if (this.path.length > 0) {
|
|
51948
|
-
const current = this.path[this.path.length - 1];
|
|
51949
|
-
if (attrValues !== null && attrValues !== void 0) current.values = attrValues;
|
|
51950
|
-
}
|
|
51951
|
-
}
|
|
51952
|
-
/**
|
|
51953
|
-
* Get current tag name.
|
|
51954
|
-
* @returns {string|undefined}
|
|
51955
|
-
*/
|
|
51956
|
-
getCurrentTag() {
|
|
51957
|
-
return this.path.length > 0 ? this.path[this.path.length - 1].tag : void 0;
|
|
51958
|
-
}
|
|
51959
|
-
/**
|
|
51960
|
-
* Get current namespace.
|
|
51961
|
-
* @returns {string|undefined}
|
|
51962
|
-
*/
|
|
51963
|
-
getCurrentNamespace() {
|
|
51964
|
-
return this.path.length > 0 ? this.path[this.path.length - 1].namespace : void 0;
|
|
51965
|
-
}
|
|
51966
|
-
/**
|
|
51967
|
-
* Get current node's attribute value.
|
|
51968
|
-
* @param {string} attrName
|
|
51969
|
-
* @returns {*}
|
|
51970
|
-
*/
|
|
51971
|
-
getAttrValue(attrName) {
|
|
51972
|
-
if (this.path.length === 0) return void 0;
|
|
51973
|
-
return this.path[this.path.length - 1].values?.[attrName];
|
|
51974
|
-
}
|
|
51975
|
-
/**
|
|
51976
|
-
* Check if current node has an attribute.
|
|
51977
|
-
* @param {string} attrName
|
|
51978
|
-
* @returns {boolean}
|
|
51979
|
-
*/
|
|
51980
|
-
hasAttr(attrName) {
|
|
51981
|
-
if (this.path.length === 0) return false;
|
|
51982
|
-
const current = this.path[this.path.length - 1];
|
|
51983
|
-
return current.values !== void 0 && attrName in current.values;
|
|
51984
|
-
}
|
|
51985
|
-
/**
|
|
51986
|
-
* Get the value of a "kept" attribute from the nearest ancestor (or
|
|
51987
|
-
* current node) that declared it via `push(tag, attrs, ns, { keep: [...] })`.
|
|
51988
|
-
* Unlike getAttrValue(), this works regardless of how deep the path has
|
|
51989
|
-
* gone since the attribute was pushed — but only for attribute names that
|
|
51990
|
-
* were explicitly marked with `keep` at push time. Cost is proportional to
|
|
51991
|
-
* the number of currently-kept attributes (typically 0-3), not path depth.
|
|
51992
|
-
* @param {string} attrName
|
|
51993
|
-
* @returns {*} the value, or undefined if no ancestor kept this attribute
|
|
51994
|
-
*/
|
|
51995
|
-
getAnyParentAttr(attrName) {
|
|
51996
|
-
const kept = this._keptAttrs;
|
|
51997
|
-
for (let i = kept.length - 1; i >= 0; i--) if (kept[i].name === attrName) return kept[i].value;
|
|
51998
|
-
}
|
|
51999
|
-
/**
|
|
52000
|
-
* Check whether any ancestor (or the current node) kept the given
|
|
52001
|
-
* attribute via `push(tag, attrs, ns, { keep: [...] })`.
|
|
52002
|
-
* @param {string} attrName
|
|
52003
|
-
* @returns {boolean}
|
|
52004
|
-
*/
|
|
52005
|
-
hasAnyParentAttr(attrName) {
|
|
52006
|
-
const kept = this._keptAttrs;
|
|
52007
|
-
for (let i = kept.length - 1; i >= 0; i--) if (kept[i].name === attrName) return true;
|
|
52008
|
-
return false;
|
|
52009
|
-
}
|
|
52010
|
-
/**
|
|
52011
|
-
* Get current node's sibling position (child index in parent).
|
|
52012
|
-
* @returns {number}
|
|
52013
|
-
*/
|
|
52014
|
-
getPosition() {
|
|
52015
|
-
if (this.path.length === 0) return -1;
|
|
52016
|
-
return this.path[this.path.length - 1].position ?? 0;
|
|
52017
|
-
}
|
|
52018
|
-
/**
|
|
52019
|
-
* Get current node's repeat counter (occurrence count of this tag name).
|
|
52020
|
-
* @returns {number}
|
|
52021
|
-
*/
|
|
52022
|
-
getCounter() {
|
|
52023
|
-
if (this.path.length === 0) return -1;
|
|
52024
|
-
return this.path[this.path.length - 1].counter ?? 0;
|
|
52025
|
-
}
|
|
52026
|
-
/**
|
|
52027
|
-
* Get current node's sibling index (alias for getPosition).
|
|
52028
|
-
* @returns {number}
|
|
52029
|
-
* @deprecated Use getPosition() or getCounter() instead
|
|
52030
|
-
*/
|
|
52031
|
-
getIndex() {
|
|
52032
|
-
return this.getPosition();
|
|
52033
|
-
}
|
|
52034
|
-
/**
|
|
52035
|
-
* Get current path depth.
|
|
52036
|
-
* @returns {number}
|
|
52037
|
-
*/
|
|
52038
|
-
getDepth() {
|
|
52039
|
-
return this.path.length;
|
|
52040
|
-
}
|
|
52041
|
-
/**
|
|
52042
|
-
* Get path as string.
|
|
52043
|
-
* @param {string} [separator] - Optional separator (uses default if not provided)
|
|
52044
|
-
* @param {boolean} [includeNamespace=true]
|
|
52045
|
-
* @returns {string}
|
|
52046
|
-
*/
|
|
52047
|
-
toString(separator, includeNamespace = true) {
|
|
52048
|
-
const sep = separator || this.separator;
|
|
52049
|
-
if (sep === this.separator && includeNamespace === true) {
|
|
52050
|
-
if (this._pathStringCache !== null) return this._pathStringCache;
|
|
52051
|
-
const result = this.path.map((n) => n.namespace ? `${n.namespace}:${n.tag}` : n.tag).join(sep);
|
|
52052
|
-
this._pathStringCache = result;
|
|
52053
|
-
return result;
|
|
52054
|
-
}
|
|
52055
|
-
return this.path.map((n) => includeNamespace && n.namespace ? `${n.namespace}:${n.tag}` : n.tag).join(sep);
|
|
52056
|
-
}
|
|
52057
|
-
/**
|
|
52058
|
-
* Get path as array of tag names.
|
|
52059
|
-
* @returns {string[]}
|
|
52060
|
-
*/
|
|
52061
|
-
toArray() {
|
|
52062
|
-
return this.path.map((n) => n.tag);
|
|
52063
|
-
}
|
|
52064
|
-
/**
|
|
52065
|
-
* Reset the path to empty.
|
|
52066
|
-
*/
|
|
52067
|
-
reset() {
|
|
52068
|
-
this._pathStringCache = null;
|
|
52069
|
-
this.path = [];
|
|
52070
|
-
this.siblingStacks = [];
|
|
52071
|
-
this._keptAttrs = [];
|
|
52072
|
-
}
|
|
52073
|
-
/**
|
|
52074
|
-
* Match current path against an Expression.
|
|
52075
|
-
* @param {Expression} expression
|
|
52076
|
-
* @returns {boolean}
|
|
52077
|
-
*/
|
|
52078
|
-
matches(expression) {
|
|
52079
|
-
const segments = expression.segments;
|
|
52080
|
-
if (segments.length === 0) return false;
|
|
52081
|
-
if (expression.hasDeepWildcard()) return this._matchWithDeepWildcard(segments);
|
|
52082
|
-
return this._matchSimple(segments);
|
|
52083
|
-
}
|
|
52084
|
-
/**
|
|
52085
|
-
* @private
|
|
52086
|
-
*/
|
|
52087
|
-
_matchSimple(segments) {
|
|
52088
|
-
if (this.path.length !== segments.length) return false;
|
|
52089
|
-
for (let i = 0; i < segments.length; i++) if (!this._matchSegment(segments[i], this.path[i], i === this.path.length - 1)) return false;
|
|
52090
|
-
return true;
|
|
52091
|
-
}
|
|
52092
|
-
/**
|
|
52093
|
-
* @private
|
|
52094
|
-
*/
|
|
52095
|
-
_matchWithDeepWildcard(segments) {
|
|
52096
|
-
let pathIdx = this.path.length - 1;
|
|
52097
|
-
let segIdx = segments.length - 1;
|
|
52098
|
-
while (segIdx >= 0 && pathIdx >= 0) {
|
|
52099
|
-
const segment = segments[segIdx];
|
|
52100
|
-
if (segment.type === "deep-wildcard") {
|
|
52101
|
-
segIdx--;
|
|
52102
|
-
if (segIdx < 0) return true;
|
|
52103
|
-
const nextSeg = segments[segIdx];
|
|
52104
|
-
let found = false;
|
|
52105
|
-
for (let i = pathIdx; i >= 0; i--) if (this._matchSegment(nextSeg, this.path[i], i === this.path.length - 1)) {
|
|
52106
|
-
pathIdx = i - 1;
|
|
52107
|
-
segIdx--;
|
|
52108
|
-
found = true;
|
|
52109
|
-
break;
|
|
52110
|
-
}
|
|
52111
|
-
if (!found) return false;
|
|
52112
|
-
} else {
|
|
52113
|
-
if (!this._matchSegment(segment, this.path[pathIdx], pathIdx === this.path.length - 1)) return false;
|
|
52114
|
-
pathIdx--;
|
|
52115
|
-
segIdx--;
|
|
52116
|
-
}
|
|
52117
|
-
}
|
|
52118
|
-
return segIdx < 0;
|
|
52119
|
-
}
|
|
52120
|
-
/**
|
|
52121
|
-
* @private
|
|
52122
|
-
*/
|
|
52123
|
-
_matchSegment(segment, node, isCurrentNode) {
|
|
52124
|
-
if (segment.tag !== "*" && segment.tag !== node.tag) return false;
|
|
52125
|
-
if (segment.namespace !== void 0) {
|
|
52126
|
-
if (segment.namespace !== "*" && segment.namespace !== node.namespace) return false;
|
|
52127
|
-
}
|
|
52128
|
-
if (segment.attrName !== void 0) {
|
|
52129
|
-
if (!isCurrentNode) return false;
|
|
52130
|
-
if (!node.values || !(segment.attrName in node.values)) return false;
|
|
52131
|
-
if (segment.attrValue !== void 0) {
|
|
52132
|
-
if (String(node.values[segment.attrName]) !== String(segment.attrValue)) return false;
|
|
52133
|
-
}
|
|
52134
|
-
}
|
|
52135
|
-
if (segment.position !== void 0) {
|
|
52136
|
-
if (!isCurrentNode) return false;
|
|
52137
|
-
const counter = node.counter ?? 0;
|
|
52138
|
-
if (segment.position === "first" && counter !== 0) return false;
|
|
52139
|
-
else if (segment.position === "odd" && counter % 2 !== 1) return false;
|
|
52140
|
-
else if (segment.position === "even" && counter % 2 !== 0) return false;
|
|
52141
|
-
else if (segment.position === "nth" && counter !== segment.positionValue) return false;
|
|
52142
|
-
}
|
|
52143
|
-
return true;
|
|
52144
|
-
}
|
|
52145
|
-
/**
|
|
52146
|
-
* Match any expression in the given set against the current path.
|
|
52147
|
-
* @param {ExpressionSet} exprSet
|
|
52148
|
-
* @returns {boolean}
|
|
52149
|
-
*/
|
|
52150
|
-
matchesAny(exprSet) {
|
|
52151
|
-
return exprSet.matchesAny(this);
|
|
52152
|
-
}
|
|
52153
|
-
/**
|
|
52154
|
-
* Create a snapshot of current state.
|
|
52155
|
-
* @returns {Object}
|
|
52156
|
-
*/
|
|
52157
|
-
snapshot() {
|
|
52158
|
-
return {
|
|
52159
|
-
path: this.path.map((node) => ({ ...node })),
|
|
52160
|
-
siblingStacks: this.siblingStacks.map((level) => level ? {
|
|
52161
|
-
counts: new Map(level.counts),
|
|
52162
|
-
total: level.total
|
|
52163
|
-
} : level),
|
|
52164
|
-
keptAttrs: this._keptAttrs.map((entry) => ({ ...entry }))
|
|
52165
|
-
};
|
|
52166
|
-
}
|
|
52167
|
-
/**
|
|
52168
|
-
* Restore state from snapshot.
|
|
52169
|
-
* @param {Object} snapshot
|
|
52170
|
-
*/
|
|
52171
|
-
restore(snapshot) {
|
|
52172
|
-
this._pathStringCache = null;
|
|
52173
|
-
this.path = snapshot.path.map((node) => ({ ...node }));
|
|
52174
|
-
this.siblingStacks = snapshot.siblingStacks.map((level) => level ? {
|
|
52175
|
-
counts: new Map(level.counts),
|
|
52176
|
-
total: level.total
|
|
52177
|
-
} : level);
|
|
52178
|
-
this._keptAttrs = (snapshot.keptAttrs || []).map((entry) => ({ ...entry }));
|
|
52179
|
-
}
|
|
52180
|
-
/**
|
|
52181
|
-
* Return the read-only {@link MatcherView} for this matcher.
|
|
52182
|
-
*
|
|
52183
|
-
* The same instance is returned on every call — no allocation occurs.
|
|
52184
|
-
* It always reflects the current parser state and is safe to pass to
|
|
52185
|
-
* user callbacks without risk of accidental mutation.
|
|
52186
|
-
*
|
|
52187
|
-
* @returns {MatcherView}
|
|
52188
|
-
*
|
|
52189
|
-
* @example
|
|
52190
|
-
* const view = matcher.readOnly();
|
|
52191
|
-
* // pass view to callbacks — it stays in sync automatically
|
|
52192
|
-
* view.matches(expr); // ✓
|
|
52193
|
-
* view.getCurrentTag(); // ✓
|
|
52194
|
-
* // view.push(...) // ✗ method does not exist — caught by TypeScript
|
|
52195
|
-
*/
|
|
52196
|
-
readOnly() {
|
|
52197
|
-
return this._view;
|
|
52198
|
-
}
|
|
52199
|
-
};
|
|
52200
|
-
//#endregion
|
|
52201
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/html.js
|
|
52202
|
-
/**
|
|
52203
|
-
* HTML context patterns.
|
|
52204
|
-
*
|
|
52205
|
-
* Detects XSS vectors that are dangerous when a string ends up rendered as HTML.
|
|
52206
|
-
* All patterns use bounded quantifiers to ensure linear-time matching (ReDoS-safe).
|
|
52207
|
-
*
|
|
52208
|
-
* Each entry is { pattern: RegExp, id: string, description: string }
|
|
52209
|
-
* so callers can inspect which rule fired if they need to.
|
|
52210
|
-
*/
|
|
52211
|
-
const HTML_PATTERNS = [
|
|
52212
|
-
{
|
|
52213
|
-
id: "html-script-open",
|
|
52214
|
-
description: "<script opening tag",
|
|
52215
|
-
pattern: /<script[\s>/]/i
|
|
52216
|
-
},
|
|
52217
|
-
{
|
|
52218
|
-
id: "html-script-close",
|
|
52219
|
-
description: "<\/script closing tag",
|
|
52220
|
-
pattern: /<\/script[\s>]/i
|
|
52221
|
-
},
|
|
52222
|
-
{
|
|
52223
|
-
id: "html-javascript-protocol",
|
|
52224
|
-
description: "javascript: URI scheme (with optional whitespace/encoding)",
|
|
52225
|
-
pattern: /j[\t\n\r ]*a[\t\n\r ]*v[\t\n\r ]*a[\t\n\r ]*s[\t\n\r ]*c[\t\n\r ]*r[\t\n\r ]*i[\t\n\r ]*p[\t\n\r ]*t[\t\n\r ]*:/i
|
|
52226
|
-
},
|
|
52227
|
-
{
|
|
52228
|
-
id: "html-vbscript-protocol",
|
|
52229
|
-
description: "vbscript: URI scheme",
|
|
52230
|
-
pattern: /vbscript[\t\n\r ]*:/i
|
|
52231
|
-
},
|
|
52232
|
-
{
|
|
52233
|
-
id: "html-data-html",
|
|
52234
|
-
description: "data:text/html URI — can execute scripts in browsers",
|
|
52235
|
-
pattern: /data[\t\n\r ]*:[\t\n\r ]*text\/html/i
|
|
52236
|
-
},
|
|
52237
|
-
{
|
|
52238
|
-
id: "html-data-xhtml",
|
|
52239
|
-
description: "data:application/xhtml+xml URI",
|
|
52240
|
-
pattern: /data[\t\n\r ]*:[\t\n\r ]*application\/xhtml/i
|
|
52241
|
-
},
|
|
52242
|
-
{
|
|
52243
|
-
id: "html-data-svg",
|
|
52244
|
-
description: "data:image/svg+xml URI — can execute scripts",
|
|
52245
|
-
pattern: /data[\t\n\r ]*:[\t\n\r ]*image\/svg\+xml/i
|
|
52246
|
-
},
|
|
52247
|
-
{
|
|
52248
|
-
id: "html-inline-event-handler",
|
|
52249
|
-
description: "Inline event handler attributes: onclick=, onerror=, onload=, etc.",
|
|
52250
|
-
pattern: /\bon\w{1,30}\s*=/i
|
|
52251
|
-
},
|
|
52252
|
-
{
|
|
52253
|
-
id: "html-entity-obfuscated-script",
|
|
52254
|
-
description: "HTML-entity-encoded <script (e.g. <script or <script)",
|
|
52255
|
-
pattern: /(?:�*3[Cc];?|�*60;?|<)\s*script/i
|
|
52256
|
-
},
|
|
52257
|
-
{
|
|
52258
|
-
id: "html-entity-obfuscated-javascript",
|
|
52259
|
-
description: "HTML-entity-encoded javascript: (partial — catches common j or j for \"j\")",
|
|
52260
|
-
pattern: /(?:�*6[Aa];?|�*106;?)\s*(?:�*61;?|a)[\s\S]{0,80}script\s*:/i
|
|
52261
|
-
},
|
|
52262
|
-
{
|
|
52263
|
-
id: "html-style-expression",
|
|
52264
|
-
description: "CSS expression() — IE-era code execution in style attributes",
|
|
52265
|
-
pattern: /style[\s\S]{0,20}expression\s*\(/i
|
|
52266
|
-
},
|
|
52267
|
-
{
|
|
52268
|
-
id: "html-object-embed",
|
|
52269
|
-
description: "<object or <embed tags that can load active content",
|
|
52270
|
-
pattern: /<(?:object|embed)[\s>/]/i
|
|
52271
|
-
},
|
|
52272
|
-
{
|
|
52273
|
-
id: "html-base-tag",
|
|
52274
|
-
description: "<base href= — can hijack all relative URLs on a page",
|
|
52275
|
-
pattern: /<base[\s>]/i
|
|
52276
|
-
},
|
|
52277
|
-
{
|
|
52278
|
-
id: "html-meta-refresh",
|
|
52279
|
-
description: "<meta http-equiv=\"refresh\" — can redirect users",
|
|
52280
|
-
pattern: /<meta[\s\S]{0,40}http-equiv[\s\S]{0,20}refresh/i
|
|
52281
|
-
},
|
|
52282
|
-
{
|
|
52283
|
-
id: "html-srcdoc",
|
|
52284
|
-
description: "srcdoc= attribute on iframes — embeds HTML that can run scripts",
|
|
52285
|
-
pattern: /srcdoc\s*=/i
|
|
52286
|
-
},
|
|
52287
|
-
{
|
|
52288
|
-
id: "html-iframe",
|
|
52289
|
-
description: "<iframe tag",
|
|
52290
|
-
pattern: /<iframe[\s>/]/i
|
|
52291
|
-
},
|
|
52292
|
-
{
|
|
52293
|
-
id: "html-form",
|
|
52294
|
-
description: "<form tag — can be used for phishing / credential harvesting injection",
|
|
52295
|
-
pattern: /<form[\s>/]/i
|
|
52296
|
-
}
|
|
52297
|
-
];
|
|
52298
|
-
//#endregion
|
|
52299
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/xml.js
|
|
52300
|
-
/**
|
|
52301
|
-
* XML context patterns.
|
|
52302
|
-
*
|
|
52303
|
-
* Detects injection vectors that are specifically dangerous when a string
|
|
52304
|
-
* is inserted into an XML document (not HTML rendering context).
|
|
52305
|
-
*
|
|
52306
|
-
* Key distinction from HTML: these patterns target parser-level attacks —
|
|
52307
|
-
* things that can confuse or subvert an XML parser, trigger external entity
|
|
52308
|
-
* resolution, or inject DTD content. HTML rendering concerns (XSS) belong
|
|
52309
|
-
* in the HTML context.
|
|
52310
|
-
*/
|
|
52311
|
-
const XML_PATTERNS = [
|
|
52312
|
-
{
|
|
52313
|
-
id: "xml-cdata-injection",
|
|
52314
|
-
description: "CDATA section injection: <![CDATA[ breaks out of text node context",
|
|
52315
|
-
pattern: /<!\[CDATA\[/i
|
|
52316
|
-
},
|
|
52317
|
-
{
|
|
52318
|
-
id: "xml-cdata-close",
|
|
52319
|
-
description: "CDATA close sequence: ]]> can terminate an enclosing CDATA section",
|
|
52320
|
-
pattern: /\]\]>/
|
|
52321
|
-
},
|
|
52322
|
-
{
|
|
52323
|
-
id: "xml-processing-instruction",
|
|
52324
|
-
description: "XML processing instruction: <?xml-stylesheet or <?php etc.",
|
|
52325
|
-
pattern: /<\?(?:xml[\- ]|php|asp)/i
|
|
52326
|
-
},
|
|
52327
|
-
{
|
|
52328
|
-
id: "xml-doctype-injection",
|
|
52329
|
-
description: "DOCTYPE declaration embedded in content — can define entities",
|
|
52330
|
-
pattern: /<!DOCTYPE(?:[\s[]|$)/i
|
|
52331
|
-
},
|
|
52332
|
-
{
|
|
52333
|
-
id: "xml-entity-system",
|
|
52334
|
-
description: "SYSTEM keyword — used in external entity declarations (XXE)",
|
|
52335
|
-
pattern: /\bSYSTEM\s+["']/i
|
|
52336
|
-
},
|
|
52337
|
-
{
|
|
52338
|
-
id: "xml-entity-public",
|
|
52339
|
-
description: "PUBLIC keyword — used in external entity declarations (XXE)",
|
|
52340
|
-
pattern: /\bPUBLIC\s+["']/i
|
|
52341
|
-
},
|
|
52342
|
-
{
|
|
52343
|
-
id: "xml-entity-declaration",
|
|
52344
|
-
description: "<!ENTITY declaration — defines entities, potential XXE or entity expansion",
|
|
52345
|
-
pattern: /<!ENTITY[\s%]/i
|
|
52346
|
-
},
|
|
52347
|
-
{
|
|
52348
|
-
id: "xml-billion-laughs",
|
|
52349
|
-
description: "Entity reference chaining / billion laughs: repeated &eX; style references",
|
|
52350
|
-
pattern: /(?:&\w{1,20};){3,}/
|
|
52351
|
-
},
|
|
52352
|
-
{
|
|
52353
|
-
id: "xml-namespace-confusion",
|
|
52354
|
-
description: "xmlns: attribute injection — can redefine namespaces to confuse parsers",
|
|
52355
|
-
pattern: /\bxmlns\s*(?::\w{1,40})?\s*=/i
|
|
52356
|
-
},
|
|
52357
|
-
{
|
|
52358
|
-
id: "xml-comment-injection",
|
|
52359
|
-
description: "<!-- comment injection — can hide content from some parsers",
|
|
52360
|
-
pattern: /<!--/
|
|
52361
|
-
},
|
|
52362
|
-
{
|
|
52363
|
-
id: "xml-comment-close",
|
|
52364
|
-
description: "--> closes an enclosing XML comment",
|
|
52365
|
-
pattern: /-->/
|
|
52366
|
-
},
|
|
52367
|
-
{
|
|
52368
|
-
id: "xml-pi-close",
|
|
52369
|
-
description: "?> closes an enclosing processing instruction",
|
|
52370
|
-
pattern: /\?>/
|
|
52371
|
-
}
|
|
52372
|
-
];
|
|
52373
|
-
//#endregion
|
|
52374
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/svg.js
|
|
52375
|
-
/**
|
|
52376
|
-
* SVG context patterns.
|
|
52377
|
-
*
|
|
52378
|
-
* SVG is XML-based but renders in browsers, giving it a unique attack surface
|
|
52379
|
-
* that combines XML parser behaviour with browser rendering and JavaScript execution.
|
|
52380
|
-
*
|
|
52381
|
-
* Many of these vectors bypass HTML sanitizers that don't understand SVG semantics
|
|
52382
|
-
* (DOMPurify has documented bypass vulnerabilities specifically in SVG/XML context).
|
|
52383
|
-
*/
|
|
52384
|
-
const SVG_PATTERNS = [
|
|
52385
|
-
{
|
|
52386
|
-
id: "svg-script-element",
|
|
52387
|
-
description: "<script element inside SVG executes JavaScript",
|
|
52388
|
-
pattern: /<script[\s>/]/i
|
|
52389
|
-
},
|
|
52390
|
-
{
|
|
52391
|
-
id: "svg-xlink-href-javascript",
|
|
52392
|
-
description: "xlink:href with javascript: — classic SVG XSS via <a> or <use>",
|
|
52393
|
-
pattern: /xlink\s*:\s*href\s*=\s*["']?\s*javascript\s*:/i
|
|
52394
|
-
},
|
|
52395
|
-
{
|
|
52396
|
-
id: "svg-href-javascript",
|
|
52397
|
-
description: "href= with javascript: in SVG context (<a>, <animate>, etc.)",
|
|
52398
|
-
pattern: /href\s*=\s*["']?\s*javascript\s*:/i
|
|
52399
|
-
},
|
|
52400
|
-
{
|
|
52401
|
-
id: "svg-foreignobject",
|
|
52402
|
-
description: "<foreignObject embeds HTML inside SVG — can execute scripts",
|
|
52403
|
-
pattern: /<foreignObject[\s>/]/i
|
|
52404
|
-
},
|
|
52405
|
-
{
|
|
52406
|
-
id: "svg-use-external",
|
|
52407
|
-
description: "<use xlink:href or href pointing to external resource (non-fragment URL)",
|
|
52408
|
-
pattern: /<use[\s\S]{0,60}(?:xlink\s*:\s*)?href\s*=\s*(?:["'][^#]|[^"'#\s>])/i
|
|
52409
|
-
},
|
|
52410
|
-
{
|
|
52411
|
-
id: "svg-animate-href",
|
|
52412
|
-
description: "<animate attributeName=\"href\" — can dynamically change href to javascript:",
|
|
52413
|
-
pattern: /<animate[\s\S]{0,80}attributeName\s*=\s*["'][\s]*href["']/i
|
|
52414
|
-
},
|
|
52415
|
-
{
|
|
52416
|
-
id: "svg-animate-xlinkhref",
|
|
52417
|
-
description: "<animate attributeName=\"xlink:href\"",
|
|
52418
|
-
pattern: /<animate[\s\S]{0,80}attributeName\s*=\s*["'][\s]*xlink\s*:\s*href["']/i
|
|
52419
|
-
},
|
|
52420
|
-
{
|
|
52421
|
-
id: "svg-set-javascript",
|
|
52422
|
-
description: "<set to=\"javascript:...\" — sets an attribute to a javascript: URI",
|
|
52423
|
-
pattern: /<set[\s\S]{0,80}to\s*=\s*["']?\s*javascript\s*:/i
|
|
52424
|
-
},
|
|
52425
|
-
{
|
|
52426
|
-
id: "svg-event-handler",
|
|
52427
|
-
description: "SVG-specific event handler attributes: onload=, onerror=, onactivate=, etc.",
|
|
52428
|
-
pattern: /\bon(?:load|error|activate|begin|end|repeat|focus|blur|click|mouse\w{1,20}|key\w{1,20})\s*=/i
|
|
52429
|
-
},
|
|
52430
|
-
{
|
|
52431
|
-
id: "svg-handler-generic",
|
|
52432
|
-
description: "Generic on* handler catch-all for SVG attributes",
|
|
52433
|
-
pattern: /\bon\w{1,30}\s*=/i
|
|
52434
|
-
},
|
|
52435
|
-
{
|
|
52436
|
-
id: "svg-filter-feimage",
|
|
52437
|
-
description: "<feImage href= — filter primitive that can load external resources",
|
|
52438
|
-
pattern: /<feImage[\s\S]{0,80}(?:xlink\s*:\s*)?href\s*=/i
|
|
52439
|
-
},
|
|
52440
|
-
{
|
|
52441
|
-
id: "svg-image-external",
|
|
52442
|
-
description: "<image xlink:href with http/https or javascript protocol",
|
|
52443
|
-
pattern: /<image[\s\S]{0,80}(?:xlink\s*:\s*)?href\s*=\s*["']?\s*(?:https?|javascript)\s*:/i
|
|
52444
|
-
},
|
|
52445
|
-
{
|
|
52446
|
-
id: "svg-style-javascript",
|
|
52447
|
-
description: "style= attribute containing javascript: (e.g. background:url(javascript:...))",
|
|
52448
|
-
pattern: /style\s*=[\s\S]{0,60}javascript\s*:/i
|
|
52449
|
-
}
|
|
52450
|
-
];
|
|
52451
|
-
//#endregion
|
|
52452
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/sql.js
|
|
52453
|
-
/**
|
|
52454
|
-
* SQL context patterns — high-precision rules only.
|
|
52455
|
-
*
|
|
52456
|
-
* These rules have very low false-positive risk and are safe to apply to
|
|
52457
|
-
* general user text (names, descriptions, search queries, etc.).
|
|
52458
|
-
* All patterns are ReDoS-safe — unlike the `sql-injection` npm package
|
|
52459
|
-
* which has an active CVE on its own detection regexes.
|
|
52460
|
-
*
|
|
52461
|
-
* For exhaustive coverage including noisier heuristics (comment sequences,
|
|
52462
|
-
* hex literals, stacked queries with semicolons), use 'SQL-STRICT' instead.
|
|
52463
|
-
* Apply 'SQL-STRICT' only to strings that are specifically SQL fragments,
|
|
52464
|
-
* not to general free-text fields.
|
|
52465
|
-
*/
|
|
52466
|
-
const SQL_PATTERNS = [
|
|
52467
|
-
{
|
|
52468
|
-
id: "sql-block-comment-open",
|
|
52469
|
-
description: "SQL block comment open: /* ... */ — unusual in legitimate user text",
|
|
52470
|
-
pattern: /\/\*/
|
|
52471
|
-
},
|
|
52472
|
-
{
|
|
52473
|
-
id: "sql-union-select",
|
|
52474
|
-
description: "UNION SELECT — most common SQL injection aggregation attack",
|
|
52475
|
-
pattern: /\bUNION\s{1,20}(?:ALL\s{1,20})?SELECT\b/i
|
|
52476
|
-
},
|
|
52477
|
-
{
|
|
52478
|
-
id: "sql-drop-table",
|
|
52479
|
-
description: "DROP TABLE — destructive DDL injection",
|
|
52480
|
-
pattern: /\bDROP\s{1,20}TABLE\b/i
|
|
52481
|
-
},
|
|
52482
|
-
{
|
|
52483
|
-
id: "sql-drop-database",
|
|
52484
|
-
description: "DROP DATABASE — destructive DDL injection",
|
|
52485
|
-
pattern: /\bDROP\s{1,20}DATABASE\b/i
|
|
52486
|
-
},
|
|
52487
|
-
{
|
|
52488
|
-
id: "sql-insert-into",
|
|
52489
|
-
description: "INSERT INTO — data injection",
|
|
52490
|
-
pattern: /\bINSERT\s{1,20}INTO\b/i
|
|
52491
|
-
},
|
|
52492
|
-
{
|
|
52493
|
-
id: "sql-delete-from",
|
|
52494
|
-
description: "DELETE FROM — data deletion injection",
|
|
52495
|
-
pattern: /\bDELETE\s{1,20}FROM\b/i
|
|
52496
|
-
},
|
|
52497
|
-
{
|
|
52498
|
-
id: "sql-update-set",
|
|
52499
|
-
description: "UPDATE ... SET — data modification injection",
|
|
52500
|
-
pattern: /\bUPDATE\b[\s\S]{1,60}\bSET\b/i
|
|
52501
|
-
},
|
|
52502
|
-
{
|
|
52503
|
-
id: "sql-exec-xp",
|
|
52504
|
-
description: "EXEC xp_ — MSSQL extended stored procedure execution",
|
|
52505
|
-
pattern: /\bEXEC(?:UTE)?\s{1,20}xp_/i
|
|
52506
|
-
},
|
|
52507
|
-
{
|
|
52508
|
-
id: "sql-tautology-string",
|
|
52509
|
-
description: "Classic string tautology: ' OR '1'='1 or \" OR \"1\"=\"1\"",
|
|
52510
|
-
pattern: /'\s{0,10}OR\s{0,10}'[^']{0,20}'\s*=\s*'[^']{0,20}/i
|
|
52511
|
-
},
|
|
52512
|
-
{
|
|
52513
|
-
id: "sql-tautology-numeric",
|
|
52514
|
-
description: "Numeric tautology: OR 1=1",
|
|
52515
|
-
pattern: /\bOR\s{1,10}1\s*=\s*1\b/i
|
|
52516
|
-
},
|
|
52517
|
-
{
|
|
52518
|
-
id: "sql-always-true-zero",
|
|
52519
|
-
description: "Numeric tautology: OR 0=0",
|
|
52520
|
-
pattern: /\bOR\s{1,10}0\s*=\s*0\b/i
|
|
52521
|
-
},
|
|
52522
|
-
{
|
|
52523
|
-
id: "sql-sleep-benchmark",
|
|
52524
|
-
description: "Time-based blind injection: SLEEP() or BENCHMARK()",
|
|
52525
|
-
pattern: /\b(?:SLEEP|BENCHMARK)\s*\(/i
|
|
52526
|
-
},
|
|
52527
|
-
{
|
|
52528
|
-
id: "sql-waitfor-delay",
|
|
52529
|
-
description: "MSSQL time-based blind injection: WAITFOR DELAY",
|
|
52530
|
-
pattern: /\bWAITFOR\s{1,20}DELAY\b/i
|
|
52531
|
-
},
|
|
52532
|
-
{
|
|
52533
|
-
id: "sql-char-function",
|
|
52534
|
-
description: "CHAR() function — used to obfuscate injected strings",
|
|
52535
|
-
pattern: /\bCHAR\s*\(\s*\d{1,3}/i
|
|
52536
|
-
},
|
|
52537
|
-
{
|
|
52538
|
-
id: "sql-information-schema",
|
|
52539
|
-
description: "INFORMATION_SCHEMA — reconnaissance query for table/column enumeration",
|
|
52540
|
-
pattern: /\bINFORMATION_SCHEMA\b/i
|
|
52541
|
-
}
|
|
52542
|
-
];
|
|
52543
|
-
//#endregion
|
|
52544
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/shell.js
|
|
52545
|
-
/**
|
|
52546
|
-
* SHELL context patterns.
|
|
52547
|
-
*
|
|
52548
|
-
* Detects shell injection vectors and path traversal patterns.
|
|
52549
|
-
* Designed for use when a string will be passed to a shell command,
|
|
52550
|
-
* used as a file path, or interpolated into OS-level operations.
|
|
52551
|
-
*/
|
|
52552
|
-
const SHELL_PATTERNS = [
|
|
52553
|
-
{
|
|
52554
|
-
id: "shell-path-traversal-unix",
|
|
52555
|
-
description: "Unix path traversal: ../ — climbing the directory tree",
|
|
52556
|
-
pattern: /\.\.\//
|
|
52557
|
-
},
|
|
52558
|
-
{
|
|
52559
|
-
id: "shell-path-traversal-windows",
|
|
52560
|
-
description: "Windows path traversal: ..\\ — climbing the directory tree",
|
|
52561
|
-
pattern: /\.\.\\/
|
|
52562
|
-
},
|
|
52563
|
-
{
|
|
52564
|
-
id: "shell-path-traversal-encoded",
|
|
52565
|
-
description: "URL-encoded path traversal: %2e%2e or %2f variants",
|
|
52566
|
-
pattern: /%2e%2e|%2f\.\.|\.\.%2f/i
|
|
52567
|
-
},
|
|
52568
|
-
{
|
|
52569
|
-
id: "shell-null-byte",
|
|
52570
|
-
description: "Null byte injection: \\x00 or %00 — truncates strings in C-backed functions",
|
|
52571
|
-
pattern: /\x00|%00/
|
|
52572
|
-
},
|
|
52573
|
-
{
|
|
52574
|
-
id: "shell-semicolon",
|
|
52575
|
-
description: "Semicolon command separator: cmd1; cmd2",
|
|
52576
|
-
pattern: /;/
|
|
52577
|
-
},
|
|
52578
|
-
{
|
|
52579
|
-
id: "shell-pipe",
|
|
52580
|
-
description: "Pipe operator: cmd1 | cmd2",
|
|
52581
|
-
pattern: /\|/
|
|
52582
|
-
},
|
|
52583
|
-
{
|
|
52584
|
-
id: "shell-and-operator",
|
|
52585
|
-
description: "AND operator: cmd1 && cmd2",
|
|
52586
|
-
pattern: /&&/
|
|
52587
|
-
},
|
|
52588
|
-
{
|
|
52589
|
-
id: "shell-or-operator",
|
|
52590
|
-
description: "OR operator: cmd1 || cmd2",
|
|
52591
|
-
pattern: /\|\|/
|
|
52592
|
-
},
|
|
52593
|
-
{
|
|
52594
|
-
id: "shell-backtick",
|
|
52595
|
-
description: "Backtick command substitution: `cmd`",
|
|
52596
|
-
pattern: /`/
|
|
52597
|
-
},
|
|
52598
|
-
{
|
|
52599
|
-
id: "shell-dollar-paren",
|
|
52600
|
-
description: "Dollar-paren command substitution: $(cmd)",
|
|
52601
|
-
pattern: /\$\(/
|
|
52602
|
-
},
|
|
52603
|
-
{
|
|
52604
|
-
id: "shell-dollar-brace",
|
|
52605
|
-
description: "Dollar-brace variable expansion: ${var} — can be abused for injection",
|
|
52606
|
-
pattern: /\$\{/
|
|
52607
|
-
},
|
|
52608
|
-
{
|
|
52609
|
-
id: "shell-redirect-out",
|
|
52610
|
-
description: "Output redirection: cmd > file or cmd >> file",
|
|
52611
|
-
pattern: />{1,2}/
|
|
52612
|
-
},
|
|
52613
|
-
{
|
|
52614
|
-
id: "shell-redirect-in",
|
|
52615
|
-
description: "Input redirection: cmd < file",
|
|
52616
|
-
pattern: /</
|
|
52617
|
-
},
|
|
52618
|
-
{
|
|
52619
|
-
id: "shell-newline-injection",
|
|
52620
|
-
description: "Newline injection: \\n or \\r — can inject new shell commands",
|
|
52621
|
-
pattern: /[\n\r]/
|
|
52622
|
-
},
|
|
52623
|
-
{
|
|
52624
|
-
id: "shell-glob-star",
|
|
52625
|
-
description: "Glob expansion: * or ? — can expand to unintended files",
|
|
52626
|
-
pattern: /[/\\][*?]/
|
|
52627
|
-
},
|
|
52628
|
-
{
|
|
52629
|
-
id: "shell-absolute-root",
|
|
52630
|
-
description: "Absolute root path injection: string starting with / or \\ (Windows UNC)",
|
|
52631
|
-
pattern: /^(?:\/|\\\\)/
|
|
52632
|
-
},
|
|
52633
|
-
{
|
|
52634
|
-
id: "shell-windows-drive",
|
|
52635
|
-
description: "Windows drive letter path injection: C:\\ or D:/",
|
|
52636
|
-
pattern: /^[a-zA-Z]:[/\\]/
|
|
52637
|
-
},
|
|
52638
|
-
{
|
|
52639
|
-
id: "shell-curl-wget",
|
|
52640
|
-
description: "curl/wget with URL or flags — can exfiltrate data or download payloads",
|
|
52641
|
-
pattern: /\b(?:curl|wget)\s+(?:https?:\/\/|ftp:\/\/|-)/i
|
|
52642
|
-
}
|
|
52643
|
-
];
|
|
52644
|
-
//#endregion
|
|
52645
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/redos.js
|
|
52646
|
-
/**
|
|
52647
|
-
* REDOS context patterns.
|
|
52648
|
-
*
|
|
52649
|
-
* Detects strings that, if used as regular expressions, could cause
|
|
52650
|
-
* catastrophic backtracking (ReDoS — Regular Expression Denial of Service).
|
|
52651
|
-
*
|
|
52652
|
-
* These patterns detect the structural forms that lead to exponential or
|
|
52653
|
-
* polynomial backtracking in NFA-based regex engines (V8, PCRE, Java, etc.).
|
|
52654
|
-
*
|
|
52655
|
-
* Use this context when user-supplied strings will be compiled into RegExp objects.
|
|
52656
|
-
*/
|
|
52657
|
-
const REDOS_PATTERNS = [
|
|
52658
|
-
{
|
|
52659
|
-
id: "redos-nested-quantifier-plus",
|
|
52660
|
-
description: "Nested + quantifier inside a group with outer quantifier: (a+)+, (.+b)*, etc.",
|
|
52661
|
-
pattern: /\([^)]*\+[^)]*\)[+*]/
|
|
52662
|
-
},
|
|
52663
|
-
{
|
|
52664
|
-
id: "redos-nested-quantifier-star",
|
|
52665
|
-
description: "Nested * quantifier: (a*)* or (a*)+ — catastrophic backtracking",
|
|
52666
|
-
pattern: /\([^)]*\*[^)]*\)[*+]/
|
|
52667
|
-
},
|
|
52668
|
-
{
|
|
52669
|
-
id: "redos-nested-groups",
|
|
52670
|
-
description: "Doubly nested quantified groups: ((a+)+) — guaranteed catastrophic",
|
|
52671
|
-
pattern: /\(\([^)]{0,40}\)[+*]\)[+*]/
|
|
52672
|
-
},
|
|
52673
|
-
{
|
|
52674
|
-
id: "redos-alternation-overlap",
|
|
52675
|
-
description: "Overlapping alternation under quantifier: (a|a)+ — ambiguous NFA paths",
|
|
52676
|
-
pattern: /\(([^|()]{1,20})\|(?:\1)(?:\|[^|()]{1,20}){0,5}\)[+*?]{1,2}/
|
|
52677
|
-
},
|
|
52678
|
-
{
|
|
52679
|
-
id: "redos-star-plus-concat",
|
|
52680
|
-
description: "(x*x)+ pattern — triggers super-linear backtracking",
|
|
52681
|
-
pattern: /\([^)]{0,10}\*[^)]{0,10}\)[+*]/
|
|
52682
|
-
},
|
|
52683
|
-
{
|
|
52684
|
-
id: "redos-dot-star-greedy",
|
|
52685
|
-
description: "(.*){n,} or (.+){n,} — repeated greedy dot quantifiers",
|
|
52686
|
-
pattern: /\(\.[*+]\)\{?\d/
|
|
52687
|
-
},
|
|
52688
|
-
{
|
|
52689
|
-
id: "redos-large-repetition",
|
|
52690
|
-
description: "Very large fixed or range repetition count {1000,} or {1000,n} — denial of service via backtracking",
|
|
52691
|
-
pattern: /\{\d{4,}(?:,\d*)?\}/
|
|
52692
|
-
},
|
|
52693
|
-
{
|
|
52694
|
-
id: "redos-catastrophic-alternation",
|
|
52695
|
-
description: "Long alternation with many similar branches — polynomial backtracking risk",
|
|
52696
|
-
pattern: /\([^)]{0,200}(?:\|[^|)]{0,50}){9,}\)/
|
|
52697
|
-
}
|
|
52698
|
-
];
|
|
52699
|
-
//#endregion
|
|
52700
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/nosql.js
|
|
52701
|
-
const sep$1 = "[\"'\\s]*:";
|
|
52702
|
-
const NOSQL_PATTERNS = [
|
|
52703
|
-
{
|
|
52704
|
-
id: "nosql-where-operator",
|
|
52705
|
-
description: "$where — executes arbitrary JavaScript server-side in MongoDB",
|
|
52706
|
-
pattern: new RegExp(`\\$where${sep$1}`, "i")
|
|
52707
|
-
},
|
|
52708
|
-
{
|
|
52709
|
-
id: "nosql-ne-operator",
|
|
52710
|
-
description: "$ne — \"not equal\" operator used to bypass equality checks",
|
|
52711
|
-
pattern: new RegExp(`\\$ne${sep$1}`, "i")
|
|
52712
|
-
},
|
|
52713
|
-
{
|
|
52714
|
-
id: "nosql-gt-operator",
|
|
52715
|
-
description: "$gt — \"greater than\" used to bypass password/value checks",
|
|
52716
|
-
pattern: new RegExp(`\\$gte?${sep$1}`, "i")
|
|
52717
|
-
},
|
|
52718
|
-
{
|
|
52719
|
-
id: "nosql-lt-operator",
|
|
52720
|
-
description: "$lt / $lte — \"less than\" bypass variants",
|
|
52721
|
-
pattern: new RegExp(`\\$lte?${sep$1}`, "i")
|
|
52722
|
-
},
|
|
52723
|
-
{
|
|
52724
|
-
id: "nosql-regex-operator",
|
|
52725
|
-
description: "$regex — can be used to extract data character by character (blind injection)",
|
|
52726
|
-
pattern: new RegExp(`\\$regex${sep$1}`, "i")
|
|
52727
|
-
},
|
|
52728
|
-
{
|
|
52729
|
-
id: "nosql-or-operator",
|
|
52730
|
-
description: "$or — logical OR; used to create always-true conditions",
|
|
52731
|
-
pattern: new RegExp(`\\$or${sep$1}\\s*\\[`, "i")
|
|
52732
|
-
},
|
|
52733
|
-
{
|
|
52734
|
-
id: "nosql-and-operator",
|
|
52735
|
-
description: "$and — logical AND operator injection",
|
|
52736
|
-
pattern: new RegExp(`\\$and${sep$1}\\s*\\[`, "i")
|
|
52737
|
-
},
|
|
52738
|
-
{
|
|
52739
|
-
id: "nosql-nor-operator",
|
|
52740
|
-
description: "$nor — logical NOR operator injection",
|
|
52741
|
-
pattern: new RegExp(`\\$nor${sep$1}\\s*\\[`, "i")
|
|
52742
|
-
},
|
|
52743
|
-
{
|
|
52744
|
-
id: "nosql-exists-operator",
|
|
52745
|
-
description: "$exists — can enumerate fields to determine schema",
|
|
52746
|
-
pattern: new RegExp(`\\$exists${sep$1}`, "i")
|
|
52747
|
-
},
|
|
52748
|
-
{
|
|
52749
|
-
id: "nosql-in-operator",
|
|
52750
|
-
description: "$in — matches any value in a list; can enumerate values",
|
|
52751
|
-
pattern: new RegExp(`\\$in${sep$1}\\s*\\[`, "i")
|
|
52752
|
-
},
|
|
52753
|
-
{
|
|
52754
|
-
id: "nosql-expr-operator",
|
|
52755
|
-
description: "$expr — allows aggregation expressions in queries (MongoDB 3.6+)",
|
|
52756
|
-
pattern: new RegExp(`\\$expr${sep$1}`, "i")
|
|
52757
|
-
},
|
|
52758
|
-
{
|
|
52759
|
-
id: "nosql-function-operator",
|
|
52760
|
-
description: "$function — executes arbitrary JavaScript in MongoDB 4.4+",
|
|
52761
|
-
pattern: new RegExp(`\\$function${sep$1}`, "i")
|
|
52762
|
-
},
|
|
52763
|
-
{
|
|
52764
|
-
id: "nosql-accumulator-operator",
|
|
52765
|
-
description: "$accumulator — custom aggregation with arbitrary JS execution",
|
|
52766
|
-
pattern: new RegExp(`\\$accumulator${sep$1}`, "i")
|
|
52767
|
-
},
|
|
52768
|
-
{
|
|
52769
|
-
id: "nosql-proto-pollution",
|
|
52770
|
-
description: "__proto__ — prototype pollution via object key injection",
|
|
52771
|
-
pattern: /__proto__/
|
|
52772
|
-
},
|
|
52773
|
-
{
|
|
52774
|
-
id: "nosql-constructor-prototype",
|
|
52775
|
-
description: "constructor.prototype — alternative prototype pollution vector (dot notation or JSON key)",
|
|
52776
|
-
pattern: /constructor[\s"':.,{\[]*prototype/i
|
|
52777
|
-
},
|
|
52778
|
-
{
|
|
52779
|
-
id: "nosql-proto-bracket",
|
|
52780
|
-
description: "[\"__proto__\"] — bracket-notation prototype pollution",
|
|
52781
|
-
pattern: /\[["']__proto__["']\]/
|
|
52782
|
-
}
|
|
52783
|
-
];
|
|
52784
|
-
//#endregion
|
|
52785
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/log.js
|
|
52786
|
-
/**
|
|
52787
|
-
* LOG context patterns.
|
|
52788
|
-
*
|
|
52789
|
-
* Detects injection vectors that are dangerous when a string is written
|
|
52790
|
-
* to a log file, passed to a logging framework, or interpolated into
|
|
52791
|
-
* a log message that will be parsed or displayed.
|
|
52792
|
-
*
|
|
52793
|
-
* Attack categories:
|
|
52794
|
-
* 1. CRLF injection — injects fake log lines by embedding newlines
|
|
52795
|
-
* 2. Log4Shell (CVE-2021-44228) — ${jndi:...} triggers JNDI lookup in Log4j
|
|
52796
|
-
* 3. SSTI in log templates — {{...}}, #{...} trigger template evaluation
|
|
52797
|
-
* if the log message is passed through a template engine
|
|
52798
|
-
* 4. Null byte injection — truncates log entries in some implementations
|
|
52799
|
-
* 5. ANSI escape injection — manipulates terminal output when logs are
|
|
52800
|
-
* tailed in a terminal (colour codes, cursor movement, etc.)
|
|
52801
|
-
*
|
|
52802
|
-
* Note: Newline characters (\n, \r) will produce false positives for
|
|
52803
|
-
* multi-line legitimate values. Use this context only for single-line
|
|
52804
|
-
* log field values (usernames, IDs, request parameters, etc.).
|
|
52805
|
-
*/
|
|
52806
|
-
const LOG_PATTERNS = [
|
|
52807
|
-
{
|
|
52808
|
-
id: "log-crlf-injection",
|
|
52809
|
-
description: "CRLF injection: literal \\r or \\n embeds fake log lines",
|
|
52810
|
-
pattern: /[\r\n]/
|
|
52811
|
-
},
|
|
52812
|
-
{
|
|
52813
|
-
id: "log-url-encoded-crlf",
|
|
52814
|
-
description: "URL-encoded CRLF: %0d, %0a, %0D, %0A — decoded by some log parsers",
|
|
52815
|
-
pattern: /%0[dDaA]/
|
|
52816
|
-
},
|
|
52817
|
-
{
|
|
52818
|
-
id: "log-unicode-newline",
|
|
52819
|
-
description: "Unicode newline variants: U+2028 (line separator), U+2029 (paragraph separator)",
|
|
52820
|
-
pattern: /[\u2028\u2029]/
|
|
52821
|
-
},
|
|
52822
|
-
{
|
|
52823
|
-
id: "log-log4shell-jndi",
|
|
52824
|
-
description: "Log4Shell: ${jndi:...} triggers remote code execution in Apache Log4j",
|
|
52825
|
-
pattern: /\$\{jndi\s*:/i
|
|
52826
|
-
},
|
|
52827
|
-
{
|
|
52828
|
-
id: "log-log4shell-obfuscated",
|
|
52829
|
-
description: "Obfuscated Log4Shell: ${::-j}... lookup-bypass prefix used to evade WAF detection",
|
|
52830
|
-
pattern: /\$\{::-/
|
|
52831
|
-
},
|
|
52832
|
-
{
|
|
52833
|
-
id: "log-log4j-lookup",
|
|
52834
|
-
description: "Log4j lookup syntax: ${env:...}, ${sys:...}, ${ctx:...} — data exfiltration",
|
|
52835
|
-
pattern: /\$\{(?:env|sys|ctx|main|map|sd|web|docker|k8s|spring)\s*:/i
|
|
52836
|
-
},
|
|
52837
|
-
{
|
|
52838
|
-
id: "log-ssti-double-brace",
|
|
52839
|
-
description: "SSTI double-brace: {{expression}} — Jinja2, Twig, Handlebars, etc.",
|
|
52840
|
-
pattern: /\{\{[\s\S]{0,80}\}\}/
|
|
52841
|
-
},
|
|
52842
|
-
{
|
|
52843
|
-
id: "log-ssti-hash-brace",
|
|
52844
|
-
description: "SSTI hash-brace: #{expression} — Thymeleaf, Velocity, Ruby ERB",
|
|
52845
|
-
pattern: /#\{[\s\S]{0,80}\}/
|
|
52846
|
-
},
|
|
52847
|
-
{
|
|
52848
|
-
id: "log-ssti-dollar-brace",
|
|
52849
|
-
description: "SSTI/EL injection: ${expression with operators or method calls} — JSP EL, Freemarker, SpEL",
|
|
52850
|
-
pattern: /\$\{[^}]*(?:\.|\(|\*|\+|\bclass\b|\bruntime\b|\bprocess\b|\bexec\b)[^}]{0,80}\}/i
|
|
52851
|
-
},
|
|
52852
|
-
{
|
|
52853
|
-
id: "log-ssti-percent-tag",
|
|
52854
|
-
description: "SSTI ERB/ASP tag: <%= expression %> — Ruby ERB, ASP",
|
|
52855
|
-
pattern: /<%=[\s\S]{0,80}%>/
|
|
52856
|
-
},
|
|
52857
|
-
{
|
|
52858
|
-
id: "log-null-byte",
|
|
52859
|
-
description: "Null byte: \\x00 or %00 — can truncate log entries in C-backed loggers",
|
|
52860
|
-
pattern: /\x00|%00/
|
|
52861
|
-
},
|
|
52862
|
-
{
|
|
52863
|
-
id: "log-ansi-escape",
|
|
52864
|
-
description: "ANSI escape sequence: ESC[ — can manipulate terminal output when logs are tailed",
|
|
52865
|
-
pattern: /\x1b\[/
|
|
52866
|
-
}
|
|
52867
|
-
];
|
|
52868
|
-
//#endregion
|
|
52869
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/contexts/sql-strict.js
|
|
52870
|
-
/**
|
|
52871
|
-
* SQL-STRICT context patterns.
|
|
52872
|
-
*
|
|
52873
|
-
* Extends the base 'SQL' context with three additional rules that are
|
|
52874
|
-
* effective at detecting real injections but carry a higher false-positive
|
|
52875
|
-
* risk on general free-text input.
|
|
52876
|
-
*
|
|
52877
|
-
* Use 'SQL-STRICT' when:
|
|
52878
|
-
* - The string is specifically a SQL fragment or database identifier
|
|
52879
|
-
* - You control the input domain (e.g. a dedicated SQL search field)
|
|
52880
|
-
* - You can tolerate occasional false positives in exchange for broader coverage
|
|
52881
|
-
*
|
|
52882
|
-
* Use 'SQL' (not STRICT) when:
|
|
52883
|
-
* - The field is general user text (names, descriptions, comments)
|
|
52884
|
-
* - False positives would block legitimate content (e.g. "see note -- above")
|
|
52885
|
-
*
|
|
52886
|
-
* Rules moved here from 'SQL' due to false-positive risk:
|
|
52887
|
-
*
|
|
52888
|
-
* sql-line-comment — "--" fires on "see note -- above", "value--", CSS var(--primary)
|
|
52889
|
-
* sql-stacked-query — "; SELECT" fires on legitimate prose with semicolons + SQL words
|
|
52890
|
-
* sql-hex-encoding — "0xDEAD" fires on hex values in technical docs and log output
|
|
52891
|
-
*/
|
|
52892
|
-
const SQL_STRICT_EXTRA = [
|
|
52893
|
-
{
|
|
52894
|
-
id: "sql-line-comment",
|
|
52895
|
-
description: "SQL line comment: -- followed by whitespace or end of string",
|
|
52896
|
-
pattern: /--(?:\s|$)/
|
|
52897
|
-
},
|
|
52898
|
-
{
|
|
52899
|
-
id: "sql-stacked-query",
|
|
52900
|
-
description: "Stacked queries: semicolon immediately followed by a SQL keyword",
|
|
52901
|
-
pattern: /;\s{0,10}(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|EXEC)\b/i
|
|
52902
|
-
},
|
|
52903
|
-
{
|
|
52904
|
-
id: "sql-hex-encoding",
|
|
52905
|
-
description: "Hex-encoded string injection: 0x41414141 style (MySQL)",
|
|
52906
|
-
pattern: /\b0x[0-9a-f]{4,}/i
|
|
52907
|
-
}
|
|
52908
|
-
];
|
|
52909
|
-
const SQL_STRICT_PATTERNS = [...SQL_PATTERNS, ...SQL_STRICT_EXTRA];
|
|
52910
|
-
//#endregion
|
|
52911
|
-
//#region ../../node_modules/.pnpm/is-unsafe@2.0.0/node_modules/is-unsafe/src/index.js
|
|
52912
|
-
HTML_PATTERNS.label = "HTML";
|
|
52913
|
-
XML_PATTERNS.label = "XML";
|
|
52914
|
-
SVG_PATTERNS.label = "SVG";
|
|
52915
|
-
SQL_PATTERNS.label = "SQL";
|
|
52916
|
-
SQL_STRICT_PATTERNS.label = "SQL-STRICT";
|
|
52917
|
-
SHELL_PATTERNS.label = "SHELL";
|
|
52918
|
-
REDOS_PATTERNS.label = "REDOS";
|
|
52919
|
-
NOSQL_PATTERNS.label = "NOSQL";
|
|
52920
|
-
LOG_PATTERNS.label = "LOG";
|
|
52921
|
-
Object.freeze({
|
|
52922
|
-
HTML: HTML_PATTERNS,
|
|
52923
|
-
XML: XML_PATTERNS,
|
|
52924
|
-
SVG: SVG_PATTERNS,
|
|
52925
|
-
SQL: SQL_PATTERNS,
|
|
52926
|
-
"SQL-STRICT": SQL_STRICT_PATTERNS,
|
|
52927
|
-
SHELL: SHELL_PATTERNS,
|
|
52928
|
-
REDOS: REDOS_PATTERNS,
|
|
52929
|
-
NOSQL: NOSQL_PATTERNS,
|
|
52930
|
-
LOG: LOG_PATTERNS
|
|
52931
|
-
});
|
|
52932
|
-
/**
|
|
52933
|
-
* @typedef {{ id: string, description: string, pattern: RegExp }} Rule
|
|
52934
|
-
*/
|
|
52935
|
-
/**
|
|
52936
|
-
* @typedef {Rule[]} PatternList
|
|
52937
|
-
*/
|
|
52938
|
-
/**
|
|
52939
|
-
* @typedef {Object} MatchResult
|
|
52940
|
-
* @property {string} context - Label identifying which context matched ('HTML', 'CUSTOM', etc.)
|
|
52941
|
-
* @property {string} id - Rule identifier
|
|
52942
|
-
* @property {string} description - Human-readable description of what was matched
|
|
52943
|
-
* @property {RegExp} pattern - The pattern that matched
|
|
52944
|
-
*/
|
|
52945
|
-
/**
|
|
52946
|
-
* @param {unknown} value
|
|
52947
|
-
*/
|
|
52948
|
-
function assertString(value) {
|
|
52949
|
-
if (typeof value !== "string") throw new TypeError(`is-unsafe: first argument must be a string, got ${typeof value}`);
|
|
52950
|
-
}
|
|
52951
|
-
/**
|
|
52952
|
-
* @param {unknown} context
|
|
52953
|
-
*/
|
|
52954
|
-
function assertContext(context) {
|
|
52955
|
-
if (context instanceof RegExp) return;
|
|
52956
|
-
if (Array.isArray(context)) {
|
|
52957
|
-
if (context.length === 0) throw new TypeError("is-unsafe: context must not be an empty array");
|
|
52958
|
-
if (Array.isArray(context[0])) {
|
|
52959
|
-
for (const list of context) if (!Array.isArray(list) || list.length === 0) throw new TypeError("is-unsafe: each context in the array must be a non-empty pattern array (PatternList)");
|
|
52960
|
-
}
|
|
52961
|
-
return;
|
|
52962
|
-
}
|
|
52963
|
-
throw new TypeError(`is-unsafe: second argument must be a PatternList (e.g. HTML), an array of PatternLists (e.g. [HTML, XML]), or a RegExp. Got: ${typeof context}`);
|
|
52964
|
-
}
|
|
52965
|
-
/**
|
|
52966
|
-
* Normalise any valid context arg into an array of PatternLists.
|
|
52967
|
-
*
|
|
52968
|
-
* @param {Rule[]|Rule[][]|RegExp} context
|
|
52969
|
-
* @returns {{ lists: Rule[][]|null, regex: RegExp|null }}
|
|
52970
|
-
*/
|
|
52971
|
-
function normalise(context) {
|
|
52972
|
-
if (context instanceof RegExp) return {
|
|
52973
|
-
lists: null,
|
|
52974
|
-
regex: context
|
|
52975
|
-
};
|
|
52976
|
-
if (Array.isArray(context[0])) return {
|
|
52977
|
-
lists: context,
|
|
52978
|
-
regex: null
|
|
52979
|
-
};
|
|
52980
|
-
return {
|
|
52981
|
-
lists: [context],
|
|
52982
|
-
regex: null
|
|
52983
|
-
};
|
|
52984
|
-
}
|
|
52985
|
-
/**
|
|
52986
|
-
* Test value against a single PatternList. Returns the first MatchResult or null.
|
|
52987
|
-
*
|
|
52988
|
-
* @param {string} value
|
|
52989
|
-
* @param {Rule[]} list
|
|
52990
|
-
* @returns {MatchResult|null}
|
|
52991
|
-
*/
|
|
52992
|
-
function matchList(value, list) {
|
|
52993
|
-
const label = list.label ?? "CUSTOM";
|
|
52994
|
-
for (const rule of list) if (rule.pattern.test(value)) return {
|
|
52995
|
-
context: label,
|
|
52996
|
-
id: rule.id,
|
|
52997
|
-
description: rule.description,
|
|
52998
|
-
pattern: rule.pattern
|
|
52999
|
-
};
|
|
53000
|
-
return null;
|
|
53001
|
-
}
|
|
53002
|
-
/**
|
|
53003
|
-
* Returns `true` if `value` is unsafe in the given context(s), `false` otherwise.
|
|
53004
|
-
*
|
|
53005
|
-
* @param {string} value - The string to test
|
|
53006
|
-
* @param {PatternList | PatternList[] | RegExp} context
|
|
53007
|
-
* - A PatternList imported from is-unsafe (e.g. `HTML`, `XML`)
|
|
53008
|
-
* - An array of PatternLists — returns true if unsafe in **any** of them
|
|
53009
|
-
* - A custom RegExp — returns true if the pattern matches
|
|
53010
|
-
* @returns {boolean}
|
|
53011
|
-
*
|
|
53012
|
-
* @example
|
|
53013
|
-
* import { isUnsafe, HTML, SQL } from 'is-unsafe';
|
|
53014
|
-
*
|
|
53015
|
-
* isUnsafe('<script>alert(1)<\/script>', HTML) // true
|
|
53016
|
-
* isUnsafe('hello world', HTML) // false
|
|
53017
|
-
* isUnsafe('value', [HTML, SQL]) // false
|
|
53018
|
-
* isUnsafe('value', /my-pattern/i) // false
|
|
53019
|
-
*/
|
|
53020
|
-
function isUnsafe(value, context) {
|
|
53021
|
-
assertString(value);
|
|
53022
|
-
assertContext(context);
|
|
53023
|
-
const { lists, regex } = normalise(context);
|
|
53024
|
-
if (regex) return regex.test(value);
|
|
53025
|
-
for (const list of lists) if (matchList(value, list) !== null) return true;
|
|
53026
|
-
return false;
|
|
53027
|
-
}
|
|
53028
|
-
//#endregion
|
|
53029
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
|
|
53030
|
-
/**
|
|
53031
|
-
* Extract raw attributes (without prefix) from prefixed attribute map
|
|
53032
|
-
* @param {object} prefixedAttrs - Attributes with prefix from buildAttributesMap
|
|
53033
|
-
* @param {object} options - Parser options containing attributeNamePrefix
|
|
53034
|
-
* @returns {object} Raw attributes for matcher
|
|
53035
|
-
*/
|
|
53036
|
-
function extractRawAttributes(prefixedAttrs, options) {
|
|
53037
|
-
if (!prefixedAttrs) return {};
|
|
53038
|
-
const attrs = options.attributesGroupName ? prefixedAttrs[options.attributesGroupName] : prefixedAttrs;
|
|
53039
|
-
if (!attrs) return {};
|
|
53040
|
-
const rawAttrs = {};
|
|
53041
|
-
for (const key in attrs) if (key.startsWith(options.attributeNamePrefix)) {
|
|
53042
|
-
const rawName = key.substring(options.attributeNamePrefix.length);
|
|
53043
|
-
rawAttrs[rawName] = attrs[key];
|
|
53044
|
-
} else rawAttrs[key] = attrs[key];
|
|
53045
|
-
return rawAttrs;
|
|
53046
|
-
}
|
|
53047
|
-
/**
|
|
53048
|
-
* Extract namespace from raw tag name
|
|
53049
|
-
* @param {string} rawTagName - Tag name possibly with namespace (e.g., "soap:Envelope")
|
|
53050
|
-
* @returns {string|undefined} Namespace or undefined
|
|
53051
|
-
*/
|
|
53052
|
-
function extractNamespace(rawTagName) {
|
|
53053
|
-
if (!rawTagName || typeof rawTagName !== "string") return void 0;
|
|
53054
|
-
const colonIndex = rawTagName.indexOf(":");
|
|
53055
|
-
if (colonIndex !== -1 && colonIndex > 0) {
|
|
53056
|
-
const ns = rawTagName.substring(0, colonIndex);
|
|
53057
|
-
if (ns !== "xmlns") return ns;
|
|
53058
|
-
}
|
|
53059
|
-
}
|
|
53060
|
-
var OrderedObjParser = class {
|
|
53061
|
-
constructor(options, externalEntities) {
|
|
53062
|
-
this.options = options;
|
|
53063
|
-
this.currentNode = null;
|
|
53064
|
-
this.tagsNodeStack = [];
|
|
53065
|
-
this.parseXml = parseXml;
|
|
53066
|
-
this.parseTextData = parseTextData;
|
|
53067
|
-
this.resolveNameSpace = resolveNameSpace;
|
|
53068
|
-
this.buildAttributesMap = buildAttributesMap;
|
|
53069
|
-
this.isItStopNode = isItStopNode;
|
|
53070
|
-
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
53071
|
-
this.readStopNodeData = readStopNodeData;
|
|
53072
|
-
this.saveTextToParentTag = saveTextToParentTag;
|
|
53073
|
-
this.addChild = addChild;
|
|
53074
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
53075
|
-
this.entityExpansionCount = 0;
|
|
53076
|
-
this.currentExpandedLength = 0;
|
|
53077
|
-
this.doctypefound = false;
|
|
53078
|
-
let namedEntities = { ...XML };
|
|
53079
|
-
if (this.options.entityDecoder) this.entityDecoder = this.options.entityDecoder;
|
|
53080
|
-
else {
|
|
53081
|
-
if (typeof this.options.htmlEntities === "object") namedEntities = this.options.htmlEntities;
|
|
53082
|
-
else if (this.options.htmlEntities === true) namedEntities = {
|
|
53083
|
-
...COMMON_HTML,
|
|
53084
|
-
...CURRENCY
|
|
53085
|
-
};
|
|
53086
|
-
this.entityDecoder = new EntityDecoder({
|
|
53087
|
-
namedEntities: {
|
|
53088
|
-
...namedEntities,
|
|
53089
|
-
...externalEntities
|
|
53090
|
-
},
|
|
53091
|
-
numericAllowed: this.options.htmlEntities,
|
|
53092
|
-
limit: {
|
|
53093
|
-
maxTotalExpansions: this.options.processEntities.maxTotalExpansions,
|
|
53094
|
-
maxExpandedLength: this.options.processEntities.maxExpandedLength,
|
|
53095
|
-
applyLimitsTo: this.options.processEntities.appliesTo
|
|
53096
|
-
},
|
|
53097
|
-
onInputEntity: (name, value) => isUnsafe(value, [HTML_PATTERNS, XML_PATTERNS]) ? ENTITY_ACTION.BLOCK : ENTITY_ACTION.ALLOW
|
|
53098
|
-
});
|
|
53099
|
-
}
|
|
53100
|
-
this.matcher = new Matcher();
|
|
53101
|
-
this.readonlyMatcher = this.matcher.readOnly();
|
|
53102
|
-
this.isCurrentNodeStopNode = false;
|
|
53103
|
-
this.stopNodeExpressionsSet = new ExpressionSet();
|
|
53104
|
-
const stopNodesOpts = this.options.stopNodes;
|
|
53105
|
-
if (stopNodesOpts && stopNodesOpts.length > 0) {
|
|
53106
|
-
for (let i = 0; i < stopNodesOpts.length; i++) {
|
|
53107
|
-
const stopNodeExp = stopNodesOpts[i];
|
|
53108
|
-
if (typeof stopNodeExp === "string") this.stopNodeExpressionsSet.add(new Expression(stopNodeExp));
|
|
53109
|
-
else if (stopNodeExp instanceof Expression) this.stopNodeExpressionsSet.add(stopNodeExp);
|
|
53110
|
-
}
|
|
53111
|
-
this.stopNodeExpressionsSet.seal();
|
|
53112
|
-
}
|
|
53113
|
-
}
|
|
53114
|
-
};
|
|
53115
|
-
/**
|
|
53116
|
-
* @param {string} val
|
|
53117
|
-
* @param {string} tagName
|
|
53118
|
-
* @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath
|
|
53119
|
-
* @param {boolean} dontTrim
|
|
53120
|
-
* @param {boolean} hasAttributes
|
|
53121
|
-
* @param {boolean} isLeafNode
|
|
53122
|
-
* @param {boolean} escapeEntities
|
|
53123
|
-
*/
|
|
53124
|
-
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
53125
|
-
const options = this.options;
|
|
53126
|
-
if (val !== void 0) {
|
|
53127
|
-
if (options.trimValues && !dontTrim) val = val.trim();
|
|
53128
|
-
if (val.length > 0) {
|
|
53129
|
-
if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath);
|
|
53130
|
-
const jPathOrMatcher = options.jPath ? jPath.toString() : jPath;
|
|
53131
|
-
const newval = options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
|
|
53132
|
-
if (newval === null || newval === void 0) return val;
|
|
53133
|
-
else if (typeof newval !== typeof val || newval !== val) return newval;
|
|
53134
|
-
else if (options.trimValues) return parseValue(val, options.parseTagValue, options.numberParseOptions);
|
|
53135
|
-
else if (val.trim() === val) return parseValue(val, options.parseTagValue, options.numberParseOptions);
|
|
53136
|
-
else return val;
|
|
53137
|
-
}
|
|
53138
|
-
}
|
|
53139
|
-
}
|
|
53140
|
-
function resolveNameSpace(tagname) {
|
|
53141
|
-
if (this.options.removeNSPrefix) {
|
|
53142
|
-
const tags = tagname.split(":");
|
|
53143
|
-
const prefix = tagname.charAt(0) === "/" ? "/" : "";
|
|
53144
|
-
if (tags[0] === "xmlns") return "";
|
|
53145
|
-
if (tags.length === 2) tagname = prefix + tags[1];
|
|
53146
|
-
}
|
|
53147
|
-
return tagname;
|
|
53148
|
-
}
|
|
53149
|
-
const attrsRegx = /* @__PURE__ */ new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?", "gm");
|
|
53150
|
-
function buildAttributesMap(attrStr, jPath, tagName, force = false) {
|
|
53151
|
-
const options = this.options;
|
|
53152
|
-
if (force === true || options.ignoreAttributes !== true && typeof attrStr === "string") {
|
|
53153
|
-
const matches = getAllMatches(attrStr, attrsRegx);
|
|
53154
|
-
const len = matches.length;
|
|
53155
|
-
const attrs = {};
|
|
53156
|
-
const processedVals = new Array(len);
|
|
53157
|
-
let hasRawAttrs = false;
|
|
53158
|
-
const rawAttrsForMatcher = {};
|
|
53159
|
-
for (let i = 0; i < len; i++) {
|
|
53160
|
-
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
53161
|
-
const oldVal = matches[i][4];
|
|
53162
|
-
if (attrName.length && oldVal !== void 0) {
|
|
53163
|
-
let val = oldVal;
|
|
53164
|
-
if (options.trimValues) val = val.trim();
|
|
53165
|
-
val = this.replaceEntitiesValue(val, tagName, this.readonlyMatcher);
|
|
53166
|
-
processedVals[i] = val;
|
|
53167
|
-
rawAttrsForMatcher[attrName] = val;
|
|
53168
|
-
hasRawAttrs = true;
|
|
53169
|
-
}
|
|
53170
|
-
}
|
|
53171
|
-
if (hasRawAttrs && typeof jPath === "object" && jPath.updateCurrent) jPath.updateCurrent(rawAttrsForMatcher);
|
|
53172
|
-
const jPathStr = options.jPath ? jPath.toString() : this.readonlyMatcher;
|
|
53173
|
-
let hasAttrs = false;
|
|
53174
|
-
for (let i = 0; i < len; i++) {
|
|
53175
|
-
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
53176
|
-
if (this.ignoreAttributesFn(attrName, jPathStr)) continue;
|
|
53177
|
-
let aName = options.attributeNamePrefix + attrName;
|
|
53178
|
-
if (attrName.length) {
|
|
53179
|
-
if (options.transformAttributeName) aName = options.transformAttributeName(aName);
|
|
53180
|
-
aName = sanitizeName(aName, options);
|
|
53181
|
-
if (matches[i][4] !== void 0) {
|
|
53182
|
-
const oldVal = processedVals[i];
|
|
53183
|
-
const newVal = options.attributeValueProcessor(attrName, oldVal, jPathStr);
|
|
53184
|
-
if (newVal === null || newVal === void 0) attrs[aName] = oldVal;
|
|
53185
|
-
else if (typeof newVal !== typeof oldVal || newVal !== oldVal) attrs[aName] = newVal;
|
|
53186
|
-
else attrs[aName] = parseValue(oldVal, options.parseAttributeValue, options.numberParseOptions);
|
|
53187
|
-
hasAttrs = true;
|
|
53188
|
-
} else if (options.allowBooleanAttributes) {
|
|
53189
|
-
attrs[aName] = true;
|
|
53190
|
-
hasAttrs = true;
|
|
53191
|
-
}
|
|
53192
|
-
}
|
|
53193
|
-
}
|
|
53194
|
-
if (!hasAttrs) return;
|
|
53195
|
-
if (options.attributesGroupName && !options.preserveOrder) {
|
|
53196
|
-
const attrCollection = {};
|
|
53197
|
-
attrCollection[options.attributesGroupName] = attrs;
|
|
53198
|
-
return attrCollection;
|
|
53199
|
-
}
|
|
53200
|
-
return attrs;
|
|
53201
|
-
}
|
|
53202
|
-
}
|
|
53203
|
-
const parseXml = function(xmlData) {
|
|
53204
|
-
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
53205
|
-
const xmlObj = new XmlNode("!xml");
|
|
53206
|
-
let currentNode = xmlObj;
|
|
53207
|
-
let textData = "";
|
|
53208
|
-
this.matcher.reset();
|
|
53209
|
-
this.entityDecoder.reset();
|
|
53210
|
-
this.entityExpansionCount = 0;
|
|
53211
|
-
this.currentExpandedLength = 0;
|
|
53212
|
-
this.doctypefound = false;
|
|
53213
|
-
const options = this.options;
|
|
53214
|
-
const docTypeReader = new DocTypeReader(options.processEntities);
|
|
53215
|
-
const xmlLen = xmlData.length;
|
|
53216
|
-
for (let i = 0; i < xmlLen; i++) if (xmlData[i] === "<") {
|
|
53217
|
-
const c1 = xmlData.charCodeAt(i + 1);
|
|
53218
|
-
if (c1 === 47) {
|
|
53219
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
53220
|
-
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
53221
|
-
if (options.removeNSPrefix) {
|
|
53222
|
-
const colonIndex = tagName.indexOf(":");
|
|
53223
|
-
if (colonIndex !== -1) tagName = tagName.substr(colonIndex + 1);
|
|
53224
|
-
}
|
|
53225
|
-
tagName = transformTagName(options.transformTagName, tagName, "", options).tagName;
|
|
53226
|
-
if (currentNode) textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
53227
|
-
const lastTagName = this.matcher.getCurrentTag();
|
|
53228
|
-
if (tagName && options.unpairedTagsSet.has(tagName)) throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
53229
|
-
if (lastTagName && options.unpairedTagsSet.has(lastTagName)) {
|
|
53230
|
-
this.matcher.pop();
|
|
53231
|
-
this.tagsNodeStack.pop();
|
|
53232
|
-
}
|
|
53233
|
-
this.matcher.pop();
|
|
53234
|
-
this.isCurrentNodeStopNode = false;
|
|
53235
|
-
currentNode = this.tagsNodeStack.pop();
|
|
53236
|
-
textData = "";
|
|
53237
|
-
i = closeIndex;
|
|
53238
|
-
} else if (c1 === 63) {
|
|
53239
|
-
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
53240
|
-
if (!tagData) throw new Error("Pi Tag is not closed.");
|
|
53241
|
-
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
53242
|
-
const attsMap = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName, true);
|
|
53243
|
-
if (attsMap) {
|
|
53244
|
-
const ver = attsMap[this.options.attributeNamePrefix + "version"];
|
|
53245
|
-
this.entityDecoder.setXmlVersion(Number(ver) || 1);
|
|
53246
|
-
docTypeReader.setXmlVersion(Number(ver) || 1);
|
|
53247
|
-
}
|
|
53248
|
-
if (options.ignoreDeclaration && tagData.tagName === "?xml" || options.ignorePiTags) {} else {
|
|
53249
|
-
const childNode = new XmlNode(tagData.tagName);
|
|
53250
|
-
childNode.add(options.textNodeName, "");
|
|
53251
|
-
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent && options.ignoreAttributes !== true) childNode[":@"] = attsMap;
|
|
53252
|
-
this.addChild(currentNode, childNode, this.readonlyMatcher, i);
|
|
53253
|
-
}
|
|
53254
|
-
i = tagData.closeIndex + 1;
|
|
53255
|
-
} else if (c1 === 33 && xmlData.charCodeAt(i + 2) === 45 && xmlData.charCodeAt(i + 3) === 45) {
|
|
53256
|
-
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
53257
|
-
if (options.commentPropName) {
|
|
53258
|
-
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
53259
|
-
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
53260
|
-
currentNode.add(options.commentPropName, [{ [options.textNodeName]: comment }]);
|
|
53261
|
-
}
|
|
53262
|
-
i = endIndex;
|
|
53263
|
-
} else if (c1 === 33 && xmlData.charCodeAt(i + 2) === 68) {
|
|
53264
|
-
if (this.doctypefound) throw new Error("Multiple DOCTYPE declarations found.");
|
|
53265
|
-
this.doctypefound = true;
|
|
53266
|
-
const result = docTypeReader.readDocType(xmlData, i);
|
|
53267
|
-
this.entityDecoder.addInputEntities(result.entities);
|
|
53268
|
-
i = result.i;
|
|
53269
|
-
} else if (c1 === 33 && xmlData.charCodeAt(i + 2) === 91) {
|
|
53270
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
53271
|
-
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
53272
|
-
textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
|
|
53273
|
-
let val = this.parseTextData(tagExp, currentNode.tagname, this.readonlyMatcher, true, false, true, true);
|
|
53274
|
-
if (val == void 0) val = "";
|
|
53275
|
-
if (options.cdataPropName) currentNode.add(options.cdataPropName, [{ [options.textNodeName]: tagExp }]);
|
|
53276
|
-
else currentNode.add(options.textNodeName, val);
|
|
53277
|
-
i = closeIndex + 2;
|
|
53278
|
-
} else {
|
|
53279
|
-
let result = readTagExp(xmlData, i, options.removeNSPrefix);
|
|
53280
|
-
if (!result) {
|
|
53281
|
-
const context = xmlData.substring(Math.max(0, i - 50), Math.min(xmlLen, i + 50));
|
|
53282
|
-
throw new Error(`readTagExp returned undefined at position ${i}. Context: "${context}"`);
|
|
53283
|
-
}
|
|
53284
|
-
let tagName = result.tagName;
|
|
53285
|
-
const rawTagName = result.rawTagName;
|
|
53286
|
-
let tagExp = result.tagExp;
|
|
53287
|
-
let attrExpPresent = result.attrExpPresent;
|
|
53288
|
-
let closeIndex = result.closeIndex;
|
|
53289
|
-
({tagName, tagExp} = transformTagName(options.transformTagName, tagName, tagExp, options));
|
|
53290
|
-
if (options.strictReservedNames && (tagName === options.commentPropName || tagName === options.cdataPropName || tagName === options.textNodeName || tagName === options.attributesGroupName)) throw new Error(`Invalid tag name: ${tagName}`);
|
|
53291
|
-
if (currentNode && textData) {
|
|
53292
|
-
if (currentNode.tagname !== "!xml") textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher, false);
|
|
53293
|
-
}
|
|
53294
|
-
const lastTag = currentNode;
|
|
53295
|
-
if (lastTag && options.unpairedTagsSet.has(lastTag.tagname)) {
|
|
53296
|
-
currentNode = this.tagsNodeStack.pop();
|
|
53297
|
-
this.matcher.pop();
|
|
53298
|
-
}
|
|
53299
|
-
let isSelfClosing = false;
|
|
53300
|
-
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
53301
|
-
isSelfClosing = true;
|
|
53302
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
53303
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
53304
|
-
tagExp = tagName;
|
|
53305
|
-
} else tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
53306
|
-
attrExpPresent = tagName !== tagExp;
|
|
53307
|
-
}
|
|
53308
|
-
let prefixedAttrs = null;
|
|
53309
|
-
let namespace = void 0;
|
|
53310
|
-
namespace = extractNamespace(rawTagName);
|
|
53311
|
-
if (tagName !== xmlObj.tagname) this.matcher.push(tagName, {}, namespace);
|
|
53312
|
-
if (tagName !== tagExp && attrExpPresent) {
|
|
53313
|
-
prefixedAttrs = this.buildAttributesMap(tagExp, this.matcher, tagName);
|
|
53314
|
-
if (prefixedAttrs) extractRawAttributes(prefixedAttrs, options);
|
|
53315
|
-
}
|
|
53316
|
-
if (tagName !== xmlObj.tagname) this.isCurrentNodeStopNode = this.isItStopNode();
|
|
53317
|
-
const startIndex = i;
|
|
53318
|
-
if (this.isCurrentNodeStopNode) {
|
|
53319
|
-
let tagContent = "";
|
|
53320
|
-
if (isSelfClosing) i = result.closeIndex;
|
|
53321
|
-
else if (options.unpairedTagsSet.has(tagName)) i = result.closeIndex;
|
|
53322
|
-
else {
|
|
53323
|
-
const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
53324
|
-
if (!result) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
53325
|
-
i = result.i;
|
|
53326
|
-
tagContent = result.tagContent;
|
|
53327
|
-
}
|
|
53328
|
-
const childNode = new XmlNode(tagName);
|
|
53329
|
-
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
53330
|
-
childNode.add(options.textNodeName, tagContent);
|
|
53331
|
-
this.matcher.pop();
|
|
53332
|
-
this.isCurrentNodeStopNode = false;
|
|
53333
|
-
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
53334
|
-
} else {
|
|
53335
|
-
if (isSelfClosing) {
|
|
53336
|
-
({tagName, tagExp} = transformTagName(options.transformTagName, tagName, tagExp, options));
|
|
53337
|
-
const childNode = new XmlNode(tagName);
|
|
53338
|
-
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
53339
|
-
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
53340
|
-
this.matcher.pop();
|
|
53341
|
-
this.isCurrentNodeStopNode = false;
|
|
53342
|
-
} else if (options.unpairedTagsSet.has(tagName)) {
|
|
53343
|
-
const childNode = new XmlNode(tagName);
|
|
53344
|
-
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
53345
|
-
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
53346
|
-
this.matcher.pop();
|
|
53347
|
-
this.isCurrentNodeStopNode = false;
|
|
53348
|
-
i = result.closeIndex;
|
|
53349
|
-
continue;
|
|
53350
|
-
} else {
|
|
53351
|
-
const childNode = new XmlNode(tagName);
|
|
53352
|
-
if (this.tagsNodeStack.length > options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
|
|
53353
|
-
this.tagsNodeStack.push(currentNode);
|
|
53354
|
-
if (prefixedAttrs) childNode[":@"] = prefixedAttrs;
|
|
53355
|
-
this.addChild(currentNode, childNode, this.readonlyMatcher, startIndex);
|
|
53356
|
-
currentNode = childNode;
|
|
53357
|
-
}
|
|
53358
|
-
textData = "";
|
|
53359
|
-
i = closeIndex;
|
|
53360
|
-
}
|
|
53361
|
-
}
|
|
53362
|
-
} else textData += xmlData[i];
|
|
53363
|
-
return xmlObj.child;
|
|
53364
|
-
};
|
|
53365
|
-
function addChild(currentNode, childNode, matcher, startIndex) {
|
|
53366
|
-
if (!this.options.captureMetaData) startIndex = void 0;
|
|
53367
|
-
const jPathOrMatcher = this.options.jPath ? matcher.toString() : matcher;
|
|
53368
|
-
const result = this.options.updateTag(childNode.tagname, jPathOrMatcher, childNode[":@"]);
|
|
53369
|
-
if (result === false) {} else if (typeof result === "string") {
|
|
53370
|
-
childNode.tagname = result;
|
|
53371
|
-
currentNode.addChild(childNode, startIndex);
|
|
53372
|
-
} else currentNode.addChild(childNode, startIndex);
|
|
53373
|
-
}
|
|
53374
|
-
/**
|
|
53375
|
-
* @param {object} val - Entity object with regex and val properties
|
|
53376
|
-
* @param {string} tagName - Tag name
|
|
53377
|
-
* @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath
|
|
53378
|
-
*/
|
|
53379
|
-
function replaceEntitiesValue(val, tagName, jPath) {
|
|
53380
|
-
const entityConfig = this.options.processEntities;
|
|
53381
|
-
if (!entityConfig || !entityConfig.enabled) return val;
|
|
53382
|
-
if (entityConfig.allowedTags) {
|
|
53383
|
-
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
53384
|
-
if (!(Array.isArray(entityConfig.allowedTags) ? entityConfig.allowedTags.includes(tagName) : entityConfig.allowedTags(tagName, jPathOrMatcher))) return val;
|
|
53385
|
-
}
|
|
53386
|
-
if (entityConfig.tagFilter) {
|
|
53387
|
-
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
53388
|
-
if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) return val;
|
|
53389
|
-
}
|
|
53390
|
-
return this.entityDecoder.decode(val);
|
|
53391
|
-
}
|
|
53392
|
-
function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
|
|
53393
|
-
if (textData) {
|
|
53394
|
-
if (isLeafNode === void 0) isLeafNode = parentNode.child.length === 0;
|
|
53395
|
-
textData = this.parseTextData(textData, parentNode.tagname, matcher, false, parentNode[":@"] ? Object.keys(parentNode[":@"]).length !== 0 : false, isLeafNode);
|
|
53396
|
-
if (textData !== void 0 && textData !== "") parentNode.add(this.options.textNodeName, textData);
|
|
53397
|
-
textData = "";
|
|
53398
|
-
}
|
|
53399
|
-
return textData;
|
|
53400
|
-
}
|
|
53401
|
-
/**
|
|
53402
|
-
* @param {Array<Expression>} stopNodeExpressions - Array of compiled Expression objects
|
|
53403
|
-
* @param {Matcher} matcher - Current path matcher
|
|
53404
|
-
*/
|
|
53405
|
-
function isItStopNode() {
|
|
53406
|
-
if (this.stopNodeExpressionsSet.size === 0) return false;
|
|
53407
|
-
return this.matcher.matchesAny(this.stopNodeExpressionsSet);
|
|
53408
|
-
}
|
|
53409
|
-
/**
|
|
53410
|
-
* Returns the tag Expression and where it is ending handling single-double quotes situation
|
|
53411
|
-
* @param {string} xmlData
|
|
53412
|
-
* @param {number} i starting index
|
|
53413
|
-
* @returns
|
|
53414
|
-
*/
|
|
53415
|
-
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
53416
|
-
let attrBoundary = 0;
|
|
53417
|
-
const len = xmlData.length;
|
|
53418
|
-
const closeCode0 = closingChar.charCodeAt(0);
|
|
53419
|
-
const closeCode1 = closingChar.length > 1 ? closingChar.charCodeAt(1) : -1;
|
|
53420
|
-
let result = "";
|
|
53421
|
-
let segmentStart = i;
|
|
53422
|
-
for (let index = i; index < len; index++) {
|
|
53423
|
-
const code = xmlData.charCodeAt(index);
|
|
53424
|
-
if (attrBoundary) {
|
|
53425
|
-
if (code === attrBoundary) attrBoundary = 0;
|
|
53426
|
-
} else if (code === 34 || code === 39) attrBoundary = code;
|
|
53427
|
-
else if (code === closeCode0) if (closeCode1 !== -1) {
|
|
53428
|
-
if (xmlData.charCodeAt(index + 1) === closeCode1) {
|
|
53429
|
-
result += xmlData.substring(segmentStart, index);
|
|
53430
|
-
return {
|
|
53431
|
-
data: result,
|
|
53432
|
-
index
|
|
53433
|
-
};
|
|
53434
|
-
}
|
|
53435
|
-
} else {
|
|
53436
|
-
result += xmlData.substring(segmentStart, index);
|
|
53437
|
-
return {
|
|
53438
|
-
data: result,
|
|
53439
|
-
index
|
|
53440
|
-
};
|
|
53441
|
-
}
|
|
53442
|
-
else if (code === 9 && !attrBoundary) {
|
|
53443
|
-
result += xmlData.substring(segmentStart, index) + " ";
|
|
53444
|
-
segmentStart = index + 1;
|
|
53445
|
-
}
|
|
53446
|
-
}
|
|
53447
|
-
}
|
|
53448
|
-
function findClosingIndex(xmlData, str, i, errMsg) {
|
|
53449
|
-
const closingIndex = xmlData.indexOf(str, i);
|
|
53450
|
-
if (closingIndex === -1) throw new Error(errMsg);
|
|
53451
|
-
else return closingIndex + str.length - 1;
|
|
53452
|
-
}
|
|
53453
|
-
function findClosingChar(xmlData, char, i, errMsg) {
|
|
53454
|
-
const closingIndex = xmlData.indexOf(char, i);
|
|
53455
|
-
if (closingIndex === -1) throw new Error(errMsg);
|
|
53456
|
-
return closingIndex;
|
|
53457
|
-
}
|
|
53458
|
-
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
|
|
53459
|
-
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
|
|
53460
|
-
if (!result) return;
|
|
53461
|
-
let tagExp = result.data;
|
|
53462
|
-
const closeIndex = result.index;
|
|
53463
|
-
const separatorIndex = tagExp.search(/\s/);
|
|
53464
|
-
let tagName = tagExp;
|
|
53465
|
-
let attrExpPresent = true;
|
|
53466
|
-
if (separatorIndex !== -1) {
|
|
53467
|
-
tagName = tagExp.substring(0, separatorIndex);
|
|
53468
|
-
tagExp = tagExp.substring(separatorIndex + 1).trimStart();
|
|
53469
|
-
}
|
|
53470
|
-
const rawTagName = tagName;
|
|
53471
|
-
if (removeNSPrefix) {
|
|
53472
|
-
const colonIndex = tagName.indexOf(":");
|
|
53473
|
-
if (colonIndex !== -1) {
|
|
53474
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
53475
|
-
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
53476
|
-
}
|
|
53477
|
-
}
|
|
53478
|
-
return {
|
|
53479
|
-
tagName,
|
|
53480
|
-
tagExp,
|
|
53481
|
-
closeIndex,
|
|
53482
|
-
attrExpPresent,
|
|
53483
|
-
rawTagName
|
|
53484
|
-
};
|
|
53485
|
-
}
|
|
53486
|
-
/**
|
|
53487
|
-
* find paired tag for a stop node
|
|
53488
|
-
* @param {string} xmlData
|
|
53489
|
-
* @param {string} tagName
|
|
53490
|
-
* @param {number} i
|
|
53491
|
-
*/
|
|
53492
|
-
function readStopNodeData(xmlData, tagName, i) {
|
|
53493
|
-
const startIndex = i;
|
|
53494
|
-
let openTagCount = 1;
|
|
53495
|
-
const xmllen = xmlData.length;
|
|
53496
|
-
for (; i < xmllen; i++) if (xmlData[i] === "<") {
|
|
53497
|
-
const c1 = xmlData.charCodeAt(i + 1);
|
|
53498
|
-
if (c1 === 47) {
|
|
53499
|
-
const closeIndex = findClosingChar(xmlData, ">", i, `${tagName} is not closed`);
|
|
53500
|
-
if (xmlData.substring(i + 2, closeIndex).trim() === tagName) {
|
|
53501
|
-
openTagCount--;
|
|
53502
|
-
if (openTagCount === 0) return {
|
|
53503
|
-
tagContent: xmlData.substring(startIndex, i),
|
|
53504
|
-
i: closeIndex
|
|
53505
|
-
};
|
|
53506
|
-
}
|
|
53507
|
-
i = closeIndex;
|
|
53508
|
-
} else if (c1 === 63) i = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
|
|
53509
|
-
else if (c1 === 33 && xmlData.charCodeAt(i + 2) === 45 && xmlData.charCodeAt(i + 3) === 45) i = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
|
|
53510
|
-
else if (c1 === 33 && xmlData.charCodeAt(i + 2) === 91) i = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
53511
|
-
else {
|
|
53512
|
-
const tagData = readTagExp(xmlData, i, false);
|
|
53513
|
-
if (tagData) {
|
|
53514
|
-
if ((tagData && tagData.tagName) === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") openTagCount++;
|
|
53515
|
-
i = tagData.closeIndex;
|
|
53516
|
-
}
|
|
53517
|
-
}
|
|
53518
|
-
}
|
|
53519
|
-
}
|
|
53520
|
-
function parseValue(val, shouldParse, options) {
|
|
53521
|
-
if (shouldParse && typeof val === "string") {
|
|
53522
|
-
const newval = val.trim();
|
|
53523
|
-
if (newval === "true") return true;
|
|
53524
|
-
else if (newval === "false") return false;
|
|
53525
|
-
else return toNumber(val, options);
|
|
53526
|
-
} else if (isExist(val)) return val;
|
|
53527
|
-
else return "";
|
|
53528
|
-
}
|
|
53529
|
-
function transformTagName(fn, tagName, tagExp, options) {
|
|
53530
|
-
if (fn) {
|
|
53531
|
-
const newTagName = fn(tagName);
|
|
53532
|
-
if (tagExp === tagName) tagExp = newTagName;
|
|
53533
|
-
tagName = newTagName;
|
|
53534
|
-
}
|
|
53535
|
-
tagName = sanitizeName(tagName, options);
|
|
53536
|
-
return {
|
|
53537
|
-
tagName,
|
|
53538
|
-
tagExp
|
|
53539
|
-
};
|
|
53540
|
-
}
|
|
53541
|
-
function sanitizeName(name, options) {
|
|
53542
|
-
if (criticalProperties.includes(name)) throw new Error(`[SECURITY] Invalid name: "${name}" is a reserved JavaScript keyword that could cause prototype pollution`);
|
|
53543
|
-
else if (DANGEROUS_PROPERTY_NAMES.includes(name)) return options.onDangerousProperty(name);
|
|
53544
|
-
return name;
|
|
53545
|
-
}
|
|
53546
|
-
//#endregion
|
|
53547
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/xmlparser/node2json.js
|
|
53548
|
-
const METADATA_SYMBOL = XmlNode.getMetaDataSymbol();
|
|
53549
|
-
/**
|
|
53550
|
-
* Helper function to strip attribute prefix from attribute map
|
|
53551
|
-
* @param {object} attrs - Attributes with prefix (e.g., {"@_class": "code"})
|
|
53552
|
-
* @param {string} prefix - Attribute prefix to remove (e.g., "@_")
|
|
53553
|
-
* @returns {object} Attributes without prefix (e.g., {"class": "code"})
|
|
53554
|
-
*/
|
|
53555
|
-
function stripAttributePrefix(attrs, prefix) {
|
|
53556
|
-
if (!attrs || typeof attrs !== "object") return {};
|
|
53557
|
-
if (!prefix) return attrs;
|
|
53558
|
-
const rawAttrs = {};
|
|
53559
|
-
for (const key in attrs) if (key.startsWith(prefix)) {
|
|
53560
|
-
const rawName = key.substring(prefix.length);
|
|
53561
|
-
rawAttrs[rawName] = attrs[key];
|
|
53562
|
-
} else rawAttrs[key] = attrs[key];
|
|
53563
|
-
return rawAttrs;
|
|
53564
|
-
}
|
|
53565
|
-
/**
|
|
53566
|
-
*
|
|
53567
|
-
* @param {array} node
|
|
53568
|
-
* @param {any} options
|
|
53569
|
-
* @param {Matcher} matcher - Path matcher instance
|
|
53570
|
-
* @returns
|
|
53571
|
-
*/
|
|
53572
|
-
function prettify(node, options, matcher, readonlyMatcher) {
|
|
53573
|
-
return compress(node, options, matcher, readonlyMatcher);
|
|
53574
|
-
}
|
|
53575
|
-
/**
|
|
53576
|
-
* @param {array} arr
|
|
53577
|
-
* @param {object} options
|
|
53578
|
-
* @param {Matcher} matcher - Path matcher instance
|
|
53579
|
-
* @returns object
|
|
53580
|
-
*/
|
|
53581
|
-
function compress(arr, options, matcher, readonlyMatcher) {
|
|
53582
|
-
let text;
|
|
53583
|
-
const compressedObj = {};
|
|
53584
|
-
for (let i = 0; i < arr.length; i++) {
|
|
53585
|
-
const tagObj = arr[i];
|
|
53586
|
-
const property = propName(tagObj);
|
|
53587
|
-
if (property !== void 0 && property !== options.textNodeName) {
|
|
53588
|
-
const rawAttrs = stripAttributePrefix(tagObj[":@"] || {}, options.attributeNamePrefix);
|
|
53589
|
-
matcher.push(property, rawAttrs);
|
|
53590
|
-
}
|
|
53591
|
-
if (property === options.textNodeName) if (text === void 0) text = tagObj[property];
|
|
53592
|
-
else text += "" + tagObj[property];
|
|
53593
|
-
else if (property === void 0) continue;
|
|
53594
|
-
else if (tagObj[property]) {
|
|
53595
|
-
let val = compress(tagObj[property], options, matcher, readonlyMatcher);
|
|
53596
|
-
const isLeaf = isLeafTag(val, options);
|
|
53597
|
-
if (Object.keys(val).length === 0 && options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
53598
|
-
if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], readonlyMatcher, options);
|
|
53599
|
-
else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) val = val[options.textNodeName];
|
|
53600
|
-
else if (Object.keys(val).length === 0) if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
53601
|
-
else val = "";
|
|
53602
|
-
if (tagObj[METADATA_SYMBOL] !== void 0 && typeof val === "object" && val !== null) val[METADATA_SYMBOL] = tagObj[METADATA_SYMBOL];
|
|
53603
|
-
if (compressedObj[property] !== void 0 && Object.prototype.hasOwnProperty.call(compressedObj, property)) {
|
|
53604
|
-
if (!Array.isArray(compressedObj[property])) compressedObj[property] = [compressedObj[property]];
|
|
53605
|
-
compressedObj[property].push(val);
|
|
53606
|
-
} else {
|
|
53607
|
-
const jPathOrMatcher = options.jPath ? readonlyMatcher.toString() : readonlyMatcher;
|
|
53608
|
-
if (options.isArray(property, jPathOrMatcher, isLeaf)) compressedObj[property] = [val];
|
|
53609
|
-
else compressedObj[property] = val;
|
|
53610
|
-
}
|
|
53611
|
-
if (property !== void 0 && property !== options.textNodeName) matcher.pop();
|
|
53612
|
-
}
|
|
53613
|
-
}
|
|
53614
|
-
if (typeof text === "string") {
|
|
53615
|
-
if (text.length > 0) compressedObj[options.textNodeName] = text;
|
|
53616
|
-
} else if (text !== void 0) compressedObj[options.textNodeName] = text;
|
|
53617
|
-
return compressedObj;
|
|
53618
|
-
}
|
|
53619
|
-
function propName(obj) {
|
|
53620
|
-
const keys = Object.keys(obj);
|
|
53621
|
-
for (let i = 0; i < keys.length; i++) {
|
|
53622
|
-
const key = keys[i];
|
|
53623
|
-
if (key !== ":@") return key;
|
|
53624
|
-
}
|
|
53625
|
-
}
|
|
53626
|
-
function assignAttributes(obj, attrMap, readonlyMatcher, options) {
|
|
53627
|
-
if (attrMap) {
|
|
53628
|
-
const keys = Object.keys(attrMap);
|
|
53629
|
-
const len = keys.length;
|
|
53630
|
-
for (let i = 0; i < len; i++) {
|
|
53631
|
-
const atrrName = keys[i];
|
|
53632
|
-
const rawAttrName = atrrName.startsWith(options.attributeNamePrefix) ? atrrName.substring(options.attributeNamePrefix.length) : atrrName;
|
|
53633
|
-
const jPathOrMatcher = options.jPath ? readonlyMatcher.toString() + "." + rawAttrName : readonlyMatcher;
|
|
53634
|
-
if (options.isArray(atrrName, jPathOrMatcher, true, true)) obj[atrrName] = [attrMap[atrrName]];
|
|
53635
|
-
else obj[atrrName] = attrMap[atrrName];
|
|
53636
|
-
}
|
|
53637
|
-
}
|
|
53638
|
-
}
|
|
53639
|
-
function isLeafTag(obj, options) {
|
|
53640
|
-
const { textNodeName } = options;
|
|
53641
|
-
const propCount = Object.keys(obj).length;
|
|
53642
|
-
if (propCount === 0) return true;
|
|
53643
|
-
if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) return true;
|
|
53644
|
-
return false;
|
|
53645
|
-
}
|
|
53646
|
-
//#endregion
|
|
53647
|
-
//#region ../../node_modules/.pnpm/fast-xml-parser@5.10.1/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
|
|
53648
|
-
var XMLParser = class {
|
|
53649
|
-
constructor(options) {
|
|
53650
|
-
this.externalEntities = {};
|
|
53651
|
-
this.options = buildOptions(options);
|
|
53652
|
-
}
|
|
53653
|
-
/**
|
|
53654
|
-
* Parse XML dats to JS object
|
|
53655
|
-
* @param {string|Uint8Array} xmlData
|
|
53656
|
-
* @param {boolean|Object} validationOption
|
|
53657
|
-
*/
|
|
53658
|
-
parse(xmlData, validationOption) {
|
|
53659
|
-
if (typeof xmlData !== "string" && xmlData.toString) xmlData = xmlData.toString();
|
|
53660
|
-
else if (typeof xmlData !== "string") throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
53661
|
-
if (validationOption) {
|
|
53662
|
-
if (validationOption === true) validationOption = {};
|
|
53663
|
-
const result = validate(xmlData, validationOption);
|
|
53664
|
-
if (result !== true) throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
53665
|
-
}
|
|
53666
|
-
const orderedObjParser = new OrderedObjParser(this.options, this.externalEntities);
|
|
53667
|
-
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
53668
|
-
if (this.options.preserveOrder || orderedResult === void 0) return orderedResult;
|
|
53669
|
-
else return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);
|
|
53670
|
-
}
|
|
53671
|
-
/**
|
|
53672
|
-
* Add Entity which is not by default supported by this library
|
|
53673
|
-
* @param {string} key
|
|
53674
|
-
* @param {string} value
|
|
53675
|
-
*/
|
|
53676
|
-
addEntity(key, value) {
|
|
53677
|
-
if (value.indexOf("&") !== -1) throw new Error("Entity value can't have '&'");
|
|
53678
|
-
else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
53679
|
-
else if (value === "&") throw new Error("An entity with value '&' is not permitted");
|
|
53680
|
-
else this.externalEntities[key] = value;
|
|
53681
|
-
}
|
|
53682
|
-
/**
|
|
53683
|
-
* Returns a Symbol that can be used to access the metadata
|
|
53684
|
-
* property on a node.
|
|
53685
|
-
*
|
|
53686
|
-
* If Symbol is not available in the environment, an ordinary property is used
|
|
53687
|
-
* and the name of the property is here returned.
|
|
53688
|
-
*
|
|
53689
|
-
* The XMLMetaData property is only present when `captureMetaData`
|
|
53690
|
-
* is true in the options.
|
|
53691
|
-
*/
|
|
53692
|
-
static getMetaDataSymbol() {
|
|
53693
|
-
return XmlNode.getMetaDataSymbol();
|
|
53694
|
-
}
|
|
53695
|
-
};
|
|
53696
|
-
//#endregion
|
|
53697
49837
|
//#region ../../node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/index.mjs
|
|
53698
49838
|
var require$1 = createRequire("/");
|
|
53699
49839
|
var _a;
|
|
@@ -54131,9 +50271,8 @@ function unzipSync(data, opts) {
|
|
|
54131
50271
|
* epub are all ZIP containers). Read-only: stored + deflate entries via
|
|
54132
50272
|
* fflate, which is pure JS and works on every platform.
|
|
54133
50273
|
*
|
|
54134
|
-
*
|
|
54135
|
-
*
|
|
54136
|
-
* fflate-backed equivalent keeps the surface tiny.
|
|
50274
|
+
* The converters only ever need `unzip`/`unzipText`, so a small fflate-backed
|
|
50275
|
+
* reader is enough; no tar support is required here.
|
|
54137
50276
|
*/
|
|
54138
50277
|
const UTF8_DECODER = new TextDecoder();
|
|
54139
50278
|
/** Read a single ZIP entry as UTF-8 text, or `undefined` when the entry is absent. */
|
|
@@ -54147,7 +50286,7 @@ function unzip(bytes) {
|
|
|
54147
50286
|
}
|
|
54148
50287
|
//#endregion
|
|
54149
50288
|
//#region ../../packages/agent-core/src/markit/converters/epub.ts
|
|
54150
|
-
const EXTENSIONS$3 = [".epub"];
|
|
50289
|
+
const EXTENSIONS$3 = new Set([".epub"]);
|
|
54151
50290
|
const MIMETYPES$3 = [
|
|
54152
50291
|
"application/epub",
|
|
54153
50292
|
"application/epub+zip",
|
|
@@ -54156,7 +50295,7 @@ const MIMETYPES$3 = [
|
|
|
54156
50295
|
var EpubConverter = class {
|
|
54157
50296
|
name = "epub";
|
|
54158
50297
|
accepts(streamInfo) {
|
|
54159
|
-
if (streamInfo.extension && EXTENSIONS$3.
|
|
50298
|
+
if (streamInfo.extension && EXTENSIONS$3.has(streamInfo.extension)) return true;
|
|
54160
50299
|
if (streamInfo.mimetype && MIMETYPES$3.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
54161
50300
|
return false;
|
|
54162
50301
|
}
|
|
@@ -54205,7 +50344,7 @@ var EpubConverter = class {
|
|
|
54205
50344
|
if (!href) continue;
|
|
54206
50345
|
const html = unzipText(entries, basePath ? `${basePath}/${href}` : href);
|
|
54207
50346
|
if (!html) continue;
|
|
54208
|
-
const cleaned = html.
|
|
50347
|
+
const cleaned = html.replaceAll(/<script[\s\S]*?<\/script>/gi, "").replaceAll(/<style[\s\S]*?<\/style>/gi, "");
|
|
54209
50348
|
const md = turndown.turndown(normalizeTablesHtml(cleaned)).trim();
|
|
54210
50349
|
if (md) sections.push(md);
|
|
54211
50350
|
}
|
|
@@ -54249,7 +50388,7 @@ function detectColumns(textBoxes) {
|
|
|
54249
50388
|
columns: [textBoxes],
|
|
54250
50389
|
boundaries: []
|
|
54251
50390
|
};
|
|
54252
|
-
const lefts = [...new Set(textBoxes.map((tb) => Math.round(tb.bounds.left)))].
|
|
50391
|
+
const lefts = [...new Set(textBoxes.map((tb) => Math.round(tb.bounds.left)))].toSorted((a, b) => a - b);
|
|
54253
50392
|
if (lefts.length < 2) return {
|
|
54254
50393
|
columnCount: 1,
|
|
54255
50394
|
columns: [textBoxes],
|
|
@@ -54311,7 +50450,7 @@ const MAX_MERGE_GAP = 14;
|
|
|
54311
50450
|
*/
|
|
54312
50451
|
function mergeIntoWords(raws) {
|
|
54313
50452
|
if (raws.length === 0) return [];
|
|
54314
|
-
const sorted = [...raws].
|
|
50453
|
+
const sorted = [...raws].toSorted((a, b) => {
|
|
54315
50454
|
const dy = b.y - a.y;
|
|
54316
50455
|
return Math.abs(dy) > SAME_LINE_Y_TOLERANCE ? dy : a.x - b.x;
|
|
54317
50456
|
});
|
|
@@ -54624,20 +50763,20 @@ function tokenizeContentStream(raw) {
|
|
|
54624
50763
|
let i = 0;
|
|
54625
50764
|
let inInlineImage = false;
|
|
54626
50765
|
while (i < len) {
|
|
54627
|
-
const ch = raw.
|
|
50766
|
+
const ch = raw.codePointAt(i);
|
|
54628
50767
|
if (ch <= 32) {
|
|
54629
50768
|
i++;
|
|
54630
50769
|
continue;
|
|
54631
50770
|
}
|
|
54632
50771
|
if (ch === 37) {
|
|
54633
|
-
while (i < len && raw.
|
|
50772
|
+
while (i < len && raw.codePointAt(i) !== 10) i++;
|
|
54634
50773
|
continue;
|
|
54635
50774
|
}
|
|
54636
50775
|
if (ch === 40) {
|
|
54637
50776
|
let depth = 1;
|
|
54638
50777
|
i++;
|
|
54639
50778
|
while (i < len && depth > 0) {
|
|
54640
|
-
const c = raw.
|
|
50779
|
+
const c = raw.codePointAt(i);
|
|
54641
50780
|
if (c === 92) i++;
|
|
54642
50781
|
else if (c === 40) depth++;
|
|
54643
50782
|
else if (c === 41) depth--;
|
|
@@ -54645,17 +50784,17 @@ function tokenizeContentStream(raw) {
|
|
|
54645
50784
|
}
|
|
54646
50785
|
continue;
|
|
54647
50786
|
}
|
|
54648
|
-
if (ch === 60 && i + 1 < len && raw.
|
|
50787
|
+
if (ch === 60 && i + 1 < len && raw.codePointAt(i + 1) !== 60) {
|
|
54649
50788
|
i++;
|
|
54650
|
-
while (i < len && raw.
|
|
50789
|
+
while (i < len && raw.codePointAt(i) !== 62) i++;
|
|
54651
50790
|
i++;
|
|
54652
50791
|
continue;
|
|
54653
50792
|
}
|
|
54654
|
-
if (ch === 60 && i + 1 < len && raw.
|
|
50793
|
+
if (ch === 60 && i + 1 < len && raw.codePointAt(i + 1) === 60) {
|
|
54655
50794
|
i += 2;
|
|
54656
50795
|
continue;
|
|
54657
50796
|
}
|
|
54658
|
-
if (ch === 62 && i + 1 < len && raw.
|
|
50797
|
+
if (ch === 62 && i + 1 < len && raw.codePointAt(i + 1) === 62) {
|
|
54659
50798
|
i += 2;
|
|
54660
50799
|
continue;
|
|
54661
50800
|
}
|
|
@@ -54665,7 +50804,7 @@ function tokenizeContentStream(raw) {
|
|
|
54665
50804
|
}
|
|
54666
50805
|
const start = i;
|
|
54667
50806
|
while (i < len) {
|
|
54668
|
-
const c = raw.
|
|
50807
|
+
const c = raw.codePointAt(i);
|
|
54669
50808
|
if (c <= 32 || c === 40 || c === 41 || c === 60 || c === 62 || c === 37) break;
|
|
54670
50809
|
i++;
|
|
54671
50810
|
}
|
|
@@ -54674,12 +50813,12 @@ function tokenizeContentStream(raw) {
|
|
|
54674
50813
|
tokens.push(token);
|
|
54675
50814
|
if (token === "BI") inInlineImage = true;
|
|
54676
50815
|
else if (token === "ID" && inInlineImage) {
|
|
54677
|
-
while (i < len && raw.
|
|
50816
|
+
while (i < len && raw.codePointAt(i) <= 32) i++;
|
|
54678
50817
|
while (i < len) {
|
|
54679
|
-
const c = raw.
|
|
54680
|
-
const prev = i === 0 ? 32 : raw.
|
|
54681
|
-
const next = i + 2 >= len ? 32 : raw.
|
|
54682
|
-
if (c === 69 && raw.
|
|
50818
|
+
const c = raw.codePointAt(i);
|
|
50819
|
+
const prev = i === 0 ? 32 : raw.codePointAt(i - 1);
|
|
50820
|
+
const next = i + 2 >= len ? 32 : raw.codePointAt(i + 2);
|
|
50821
|
+
if (c === 69 && raw.codePointAt(i + 1) === 73 && prev <= 32 && next <= 32) {
|
|
54683
50822
|
i += 2;
|
|
54684
50823
|
break;
|
|
54685
50824
|
}
|
|
@@ -54871,13 +51010,13 @@ function castRaysForTextBox(textBox, segments) {
|
|
|
54871
51010
|
const AXIS_EPSILON = .8;
|
|
54872
51011
|
const PAGE_MARGIN = 20;
|
|
54873
51012
|
function uniqueSorted(values) {
|
|
54874
|
-
const sorted = [...values].
|
|
51013
|
+
const sorted = [...values].toSorted((a, b) => a - b);
|
|
54875
51014
|
const result = [];
|
|
54876
|
-
for (const v of sorted) if (result.length === 0 || Math.abs(result
|
|
51015
|
+
for (const v of sorted) if (result.length === 0 || Math.abs(result.at(-1) - v) > 1) result.push(v);
|
|
54877
51016
|
return result;
|
|
54878
51017
|
}
|
|
54879
51018
|
function chainCoversRange(intervals, lowerY, upperY, eps) {
|
|
54880
|
-
const sorted = [...intervals].
|
|
51019
|
+
const sorted = [...intervals].toSorted((a, b) => a.min - b.min);
|
|
54881
51020
|
let covered = lowerY;
|
|
54882
51021
|
for (const iv of sorted) {
|
|
54883
51022
|
if (iv.min > covered + eps) break;
|
|
@@ -54981,9 +51120,9 @@ function expandSubRowsByYClusters(originalRows, cols, cells, cellBoxes) {
|
|
|
54981
51120
|
}
|
|
54982
51121
|
if (rowCellInfos.length === 0) continue;
|
|
54983
51122
|
const allMidYs = rowCellInfos.flatMap(({ boxes }) => boxes.map((b) => (b.bounds.top + b.bounds.bottom) / 2));
|
|
54984
|
-
const sortedY = [...new Set(allMidYs.map((y) => Math.round(y * 10) / 10))].
|
|
51123
|
+
const sortedY = [...new Set(allMidYs.map((y) => Math.round(y * 10) / 10))].toSorted((a, b) => b - a);
|
|
54985
51124
|
const clusters = [sortedY[0]];
|
|
54986
|
-
for (let i = 1; i < sortedY.length; i++) if (clusters
|
|
51125
|
+
for (let i = 1; i < sortedY.length; i++) if (clusters.at(-1) - sortedY[i] > Y_CLUSTER_GAP) clusters.push(sortedY[i]);
|
|
54987
51126
|
if (clusters.length < 2) continue;
|
|
54988
51127
|
const colsInTopCluster = /* @__PURE__ */ new Set();
|
|
54989
51128
|
const totalNonEmptyCols = /* @__PURE__ */ new Set();
|
|
@@ -55131,10 +51270,10 @@ function buildTableGrid(pageNumber, yLines, xLines, filteredSegments, textBoxes)
|
|
|
55131
51270
|
const cols = xLines.length - 1;
|
|
55132
51271
|
const cells = buildCells(rows, cols);
|
|
55133
51272
|
const consumedIds = [];
|
|
55134
|
-
const yMin = yLines
|
|
51273
|
+
const yMin = yLines.at(-1);
|
|
55135
51274
|
const yMax = yLines[0];
|
|
55136
51275
|
const xMin = xLines[0];
|
|
55137
|
-
const xMax = xLines
|
|
51276
|
+
const xMax = xLines.at(-1);
|
|
55138
51277
|
const splitBoxes = splitCrossColumnBoxes(textBoxes, xLines);
|
|
55139
51278
|
const placedSplitIds = /* @__PURE__ */ new Set();
|
|
55140
51279
|
const maxHeaderBoxWidth = (xMax - xMin) / cols * 1.5;
|
|
@@ -55232,7 +51371,7 @@ const HONLY_ROW_TOLERANCE = 8;
|
|
|
55232
51371
|
const MIN_TABLE_HEIGHT = 24;
|
|
55233
51372
|
const MIN_LEFT_SPREAD = 50;
|
|
55234
51373
|
function inferXLinesFromBoxes(textBoxes, xMin, xMax) {
|
|
55235
|
-
const centers = textBoxes.map((tb) => (tb.bounds.left + tb.bounds.right) / 2).
|
|
51374
|
+
const centers = textBoxes.map((tb) => (tb.bounds.left + tb.bounds.right) / 2).toSorted((a, b) => a - b);
|
|
55236
51375
|
if (centers.length === 0) return [xMin, xMax];
|
|
55237
51376
|
const boundaries = [xMin];
|
|
55238
51377
|
for (let i = 1; i < centers.length; i++) if (centers[i] - centers[i - 1] >= COL_GAP_THRESHOLD) boundaries.push((centers[i - 1] + centers[i]) / 2);
|
|
@@ -55241,7 +51380,7 @@ function inferXLinesFromBoxes(textBoxes, xMin, xMax) {
|
|
|
55241
51380
|
}
|
|
55242
51381
|
function buildHLineOnlyTable(pageNumber, yLines, xMin, xMax, textBoxes, alreadyConsumed) {
|
|
55243
51382
|
const yMax = yLines[0];
|
|
55244
|
-
const yMin = yLines
|
|
51383
|
+
const yMin = yLines.at(-1);
|
|
55245
51384
|
const candidates = textBoxes.filter((tb) => !alreadyConsumed.has(tb.id));
|
|
55246
51385
|
const BOX_LEFT_TOLERANCE = 30;
|
|
55247
51386
|
const inRange = candidates.filter((tb) => {
|
|
@@ -55252,7 +51391,7 @@ function buildHLineOnlyTable(pageNumber, yLines, xMin, xMax, textBoxes, alreadyC
|
|
|
55252
51391
|
const cx = (tb.bounds.left + tb.bounds.right) / 2;
|
|
55253
51392
|
const cy = (tb.bounds.top + tb.bounds.bottom) / 2;
|
|
55254
51393
|
return cx >= xMin && cx <= xMax && cy < yMin;
|
|
55255
|
-
}).
|
|
51394
|
+
}).toSorted((a, b) => (b.bounds.top + b.bounds.bottom) / 2 - (a.bounds.top + a.bounds.bottom) / 2);
|
|
55256
51395
|
const extensionBoxes = [];
|
|
55257
51396
|
let lastY = yMin;
|
|
55258
51397
|
for (const tb of belowYMin) {
|
|
@@ -55269,7 +51408,7 @@ function buildHLineOnlyTable(pageNumber, yLines, xMin, xMax, textBoxes, alreadyC
|
|
|
55269
51408
|
if (xLines.length < 2) return null;
|
|
55270
51409
|
const cols = xLines.length - 1;
|
|
55271
51410
|
const visualRows = [];
|
|
55272
|
-
const sortedBoxes = [...allBoxes].
|
|
51411
|
+
const sortedBoxes = [...allBoxes].toSorted((a, b) => {
|
|
55273
51412
|
const ya = (a.bounds.top + a.bounds.bottom) / 2;
|
|
55274
51413
|
const yb = (b.bounds.top + b.bounds.bottom) / 2;
|
|
55275
51414
|
if (Math.abs(ya - yb) > .5) return yb - ya;
|
|
@@ -55277,7 +51416,7 @@ function buildHLineOnlyTable(pageNumber, yLines, xMin, xMax, textBoxes, alreadyC
|
|
|
55277
51416
|
});
|
|
55278
51417
|
for (const box of sortedBoxes) {
|
|
55279
51418
|
const cy = (box.bounds.top + box.bounds.bottom) / 2;
|
|
55280
|
-
const last = visualRows
|
|
51419
|
+
const last = visualRows.at(-1);
|
|
55281
51420
|
if (last && Math.abs(last.midY - cy) <= HONLY_ROW_TOLERANCE) last.boxes.push(box);
|
|
55282
51421
|
else visualRows.push({
|
|
55283
51422
|
midY: cy,
|
|
@@ -55302,7 +51441,7 @@ function buildHLineOnlyTable(pageNumber, yLines, xMin, xMax, textBoxes, alreadyC
|
|
|
55302
51441
|
}
|
|
55303
51442
|
}
|
|
55304
51443
|
for (let c = 0; c < cols; c++) {
|
|
55305
|
-
const cbs = (colBoxes.get(c) ?? []).
|
|
51444
|
+
const cbs = (colBoxes.get(c) ?? []).toSorted((a, b) => a.bounds.left - b.bounds.left);
|
|
55306
51445
|
cells.push({
|
|
55307
51446
|
row: rowIdx,
|
|
55308
51447
|
col: c,
|
|
@@ -55395,7 +51534,7 @@ function resolveTableGrids(pageNumber, textBoxes, segments) {
|
|
|
55395
51534
|
const segMin = Math.min(s.y1, s.y2);
|
|
55396
51535
|
return Math.max(s.y1, s.y2) >= textYMin && segMin <= textYMax && s.x1 >= textXMin && s.x1 <= vSegXMax;
|
|
55397
51536
|
});
|
|
55398
|
-
const allYLines = uniqueSorted(filteredH.flatMap((s) => [s.y1, s.y2])).
|
|
51537
|
+
const allYLines = uniqueSorted(filteredH.flatMap((s) => [s.y1, s.y2])).toSorted((a, b) => b - a);
|
|
55399
51538
|
if (allYLines.length < 2) return {
|
|
55400
51539
|
grids: [],
|
|
55401
51540
|
consumedIds: []
|
|
@@ -55407,7 +51546,7 @@ function resolveTableGrids(pageNumber, textBoxes, segments) {
|
|
|
55407
51546
|
const allConsumedIds = [];
|
|
55408
51547
|
for (const yLines of yGroups) {
|
|
55409
51548
|
if (yLines.length < 2) continue;
|
|
55410
|
-
const yMin = yLines
|
|
51549
|
+
const yMin = yLines.at(-1);
|
|
55411
51550
|
const yMax = yLines[0];
|
|
55412
51551
|
const groupXLines = uniqueSorted(filteredV.filter((s) => {
|
|
55413
51552
|
const segMin = Math.min(s.y1, s.y2);
|
|
@@ -55475,7 +51614,7 @@ function stripHeadersFooters(pages) {
|
|
|
55475
51614
|
for (const tb of page.textBoxes) {
|
|
55476
51615
|
const midY = (tb.bounds.top + tb.bounds.bottom) / 2;
|
|
55477
51616
|
if (midY >= TOP_ZONE_MIN_Y || midY <= BOTTOM_ZONE_MAX_Y) {
|
|
55478
|
-
const key = tb.text.trim().
|
|
51617
|
+
const key = tb.text.trim().replaceAll(/\s+/g, " ");
|
|
55479
51618
|
if (key.length > 0) zoneTexts.add(key);
|
|
55480
51619
|
}
|
|
55481
51620
|
}
|
|
@@ -55512,7 +51651,7 @@ function stripHeadersFooters(pages) {
|
|
|
55512
51651
|
for (const page of pages) page.textBoxes = page.textBoxes.filter((tb) => {
|
|
55513
51652
|
const midY = (tb.bounds.top + tb.bounds.bottom) / 2;
|
|
55514
51653
|
if (midY < TOP_ZONE_MIN_Y && midY > BOTTOM_ZONE_MAX_Y) return true;
|
|
55515
|
-
const normalized = tb.text.trim().
|
|
51654
|
+
const normalized = tb.text.trim().replaceAll(/\s+/g, " ");
|
|
55516
51655
|
return !repeatedTexts.has(normalized);
|
|
55517
51656
|
});
|
|
55518
51657
|
}
|
|
@@ -55520,7 +51659,7 @@ function stripHeadersFooters(pages) {
|
|
|
55520
51659
|
//#region ../../packages/agent-core/src/markit/converters/pdf/render.ts
|
|
55521
51660
|
/** Convert full-width ASCII characters (A→A, !→! etc.) to normal ASCII. */
|
|
55522
51661
|
function normalizeFullWidthAscii(text) {
|
|
55523
|
-
return text.
|
|
51662
|
+
return text.replaceAll(/[!-~]/g, (ch) => String.fromCodePoint(ch.codePointAt(0) - 65248));
|
|
55524
51663
|
}
|
|
55525
51664
|
function escapePipes(text) {
|
|
55526
51665
|
return normalizeFullWidthAscii(text).replaceAll("|", "\\|").replaceAll("\n", "<br>");
|
|
@@ -55660,7 +51799,7 @@ function modalFontSize(textBoxes) {
|
|
|
55660
51799
|
/** Group free text boxes into horizontal lines, sorted top-to-bottom. */
|
|
55661
51800
|
function groupFreeTextIntoLines(textBoxes) {
|
|
55662
51801
|
if (textBoxes.length === 0) return [];
|
|
55663
|
-
const sorted = [...textBoxes].
|
|
51802
|
+
const sorted = [...textBoxes].toSorted((a, b) => {
|
|
55664
51803
|
const ya = (a.bounds.top + a.bounds.bottom) / 2;
|
|
55665
51804
|
const dy = (b.bounds.top + b.bounds.bottom) / 2 - ya;
|
|
55666
51805
|
if (Math.abs(dy) > TEXT_LINE_Y_TOLERANCE) return dy;
|
|
@@ -55926,7 +52065,7 @@ function renderPageContent(freeTextBoxes, tables, imageBlocks = [], allTextBoxes
|
|
|
55926
52065
|
* 4. Render diagrams as PNG files (if output directory provided)
|
|
55927
52066
|
* 5. Render tables as markdown tables, free text as paragraphs/headings
|
|
55928
52067
|
*/
|
|
55929
|
-
const EXTENSIONS$2 = [".pdf"];
|
|
52068
|
+
const EXTENSIONS$2 = new Set([".pdf"]);
|
|
55930
52069
|
const MIMETYPES$2 = ["application/pdf", "application/x-pdf"];
|
|
55931
52070
|
/**
|
|
55932
52071
|
* Process a set of text boxes (one column or full page): run table detection,
|
|
@@ -55940,7 +52079,7 @@ function processColumn(pageNumber, textBoxes, segments, imageBlocks) {
|
|
|
55940
52079
|
var PdfConverter = class {
|
|
55941
52080
|
name = "pdf";
|
|
55942
52081
|
accepts(streamInfo) {
|
|
55943
|
-
if (streamInfo.extension && EXTENSIONS$2.
|
|
52082
|
+
if (streamInfo.extension && EXTENSIONS$2.has(streamInfo.extension)) return true;
|
|
55944
52083
|
if (streamInfo.mimetype && MIMETYPES$2.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
55945
52084
|
return false;
|
|
55946
52085
|
}
|
|
@@ -56007,12 +52146,12 @@ var PdfConverter = class {
|
|
|
56007
52146
|
};
|
|
56008
52147
|
//#endregion
|
|
56009
52148
|
//#region ../../packages/agent-core/src/markit/converters/pptx.ts
|
|
56010
|
-
const EXTENSIONS$1 = [".pptx"];
|
|
52149
|
+
const EXTENSIONS$1 = new Set([".pptx"]);
|
|
56011
52150
|
const MIMETYPES$1 = ["application/vnd.openxmlformats-officedocument.presentationml.presentation"];
|
|
56012
52151
|
var PptxConverter = class {
|
|
56013
52152
|
name = "pptx";
|
|
56014
52153
|
accepts(streamInfo) {
|
|
56015
|
-
if (streamInfo.extension && EXTENSIONS$1.
|
|
52154
|
+
if (streamInfo.extension && EXTENSIONS$1.has(streamInfo.extension)) return true;
|
|
56016
52155
|
if (streamInfo.mimetype && MIMETYPES$1.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
56017
52156
|
return false;
|
|
56018
52157
|
}
|
|
@@ -56040,7 +52179,7 @@ var PptxConverter = class {
|
|
|
56040
52179
|
if (target) slidePaths.push(`ppt/${target}`);
|
|
56041
52180
|
}
|
|
56042
52181
|
if (slidePaths.length === 0) {
|
|
56043
|
-
const slideFiles = Object.keys(entries).filter((f) => /^ppt\/slides\/slide\d+\.xml$/.test(f)).
|
|
52182
|
+
const slideFiles = Object.keys(entries).filter((f) => /^ppt\/slides\/slide\d+\.xml$/.test(f)).toSorted((a, b) => {
|
|
56044
52183
|
return parseInt(a.match(/slide(\d+)/)?.[1] || "0", 10) - parseInt(b.match(/slide(\d+)/)?.[1] || "0", 10);
|
|
56045
52184
|
});
|
|
56046
52185
|
slidePaths.push(...slideFiles);
|
|
@@ -56193,12 +52332,12 @@ function toList(val) {
|
|
|
56193
52332
|
}
|
|
56194
52333
|
//#endregion
|
|
56195
52334
|
//#region ../../packages/agent-core/src/markit/converters/xlsx.ts
|
|
56196
|
-
const EXTENSIONS = [".xlsx"];
|
|
52335
|
+
const EXTENSIONS = new Set([".xlsx"]);
|
|
56197
52336
|
const MIMETYPES = ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
|
|
56198
52337
|
var XlsxConverter = class {
|
|
56199
52338
|
name = "xlsx";
|
|
56200
52339
|
accepts(streamInfo) {
|
|
56201
|
-
if (streamInfo.extension && EXTENSIONS.
|
|
52340
|
+
if (streamInfo.extension && EXTENSIONS.has(streamInfo.extension)) return true;
|
|
56202
52341
|
if (streamInfo.mimetype && MIMETYPES.some((m) => streamInfo.mimetype?.startsWith(m))) return true;
|
|
56203
52342
|
return false;
|
|
56204
52343
|
}
|
|
@@ -56283,11 +52422,11 @@ function toArray(val) {
|
|
|
56283
52422
|
//#endregion
|
|
56284
52423
|
//#region ../../packages/agent-core/src/markit/registry.ts
|
|
56285
52424
|
/**
|
|
56286
|
-
* In-house document → markdown engine
|
|
52425
|
+
* In-house document → markdown engine.
|
|
56287
52426
|
*
|
|
56288
|
-
* Only the document converters
|
|
56289
|
-
* xlsx, epub). The first converter whose `accepts()` returns true and
|
|
56290
|
-
* `convert()` succeeds wins.
|
|
52427
|
+
* Only the document converters this codebase needs are registered (pdf, docx,
|
|
52428
|
+
* pptx, xlsx, epub). The first converter whose `accepts()` returns true and
|
|
52429
|
+
* whose `convert()` succeeds wins.
|
|
56291
52430
|
*/
|
|
56292
52431
|
var Markit = class {
|
|
56293
52432
|
#converters;
|
|
@@ -56318,10 +52457,10 @@ var Markit = class {
|
|
|
56318
52457
|
if (!converter.accepts(streamInfo)) continue;
|
|
56319
52458
|
try {
|
|
56320
52459
|
return await converter.convert(input, streamInfo, this.#options);
|
|
56321
|
-
} catch (
|
|
52460
|
+
} catch (error) {
|
|
56322
52461
|
errors.push({
|
|
56323
52462
|
converter: converter.name,
|
|
56324
|
-
error:
|
|
52463
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
56325
52464
|
});
|
|
56326
52465
|
}
|
|
56327
52466
|
}
|