: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function isWhitespace(s, index) {
return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
function isWhitespaceString(s) {
for (let i = 0, ii = s.length; i < ii; i++) {
if (!isWhitespace(s, i)) {
return s.replaceAll(/&([^;]+);/g, (all, entity) => {
if (entity.substring(0, 2) === "#x") {
return String.fromCodePoint(parseInt(entity.substring(2), 16));
} else if (entity.substring(0, 1) === "#") {
return String.fromCodePoint(parseInt(entity.substring(1), 10));
return this.onResolveEntity(entity);
_parseContent(s, start) {
while (pos < s.length && isWhitespace(s, pos)) {
while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
const name = s.substring(start, pos);
while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
const attrEndChar = s[pos];
if (attrEndChar !== '"' && attrEndChar !== "'") {
const attrEndIndex = s.indexOf(attrEndChar, ++pos);
attrValue = s.substring(pos, attrEndIndex);
value: this._resolveEntities(attrValue)
_parseProcessingInstruction(s, start) {
while (pos < s.length && isWhitespace(s, pos)) {
while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "?" && s[pos] !== "/") {
const name = s.substring(start, pos);
while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
const value = s.substring(attrStart, pos);
this.onError(XMLParserErrorCode.UnterminatedElement);
this.onEndElement(s.substring(j, q));
const pi = this._parseProcessingInstruction(s, j);
if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
this.onPi(pi.name, pi.value);
if (s.substring(j + 1, j + 3) === "--") {
q = s.indexOf("-->", j + 3);
this.onError(XMLParserErrorCode.UnterminatedComment);
this.onComment(s.substring(j + 3, q));
} else if (s.substring(j + 1, j + 8) === "[CDATA[") {
q = s.indexOf("]]>", j + 8);
this.onError(XMLParserErrorCode.UnterminatedCdat);
this.onCdata(s.substring(j + 8, q));
} else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
const q2 = s.indexOf("[", j + 8);
let complexDoctype = false;
q = s.indexOf(">", j + 8);
this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
q = s.indexOf("]>", j + 8);
this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
this.onDoctype(doctypeContent);
j = q + (complexDoctype ? 2 : 1);
this.onError(XMLParserErrorCode.MalformedElement);
const content = this._parseContent(s, j);
this.onError(XMLParserErrorCode.MalformedElement);
if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
} else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
this.onError(XMLParserErrorCode.UnterminatedElement);
this.onBeginElement(content.name, content.attributes, isClosed);
j += content.parsed + (isClosed ? 2 : 1);
while (j < s.length && s[j] !== "<") {
const text = s.substring(i, j);
this.onText(this._resolveEntities(text));
onDoctype(doctypeContent) {}
onBeginElement(name, attributes, isEmpty) {}
constructor(nodeName, nodeValue) {
this.nodeName = nodeName;
this.nodeValue = nodeValue;
Object.defineProperty(this, "parentNode", {
return this.childNodes?.[0];
const childNodes = this.parentNode.childNodes;
const index = childNodes.indexOf(this);
return childNodes[index + 1];
return this.nodeValue || "";
return this.childNodes.map(function (child) {
return child.textContent;
return this.childNodes || [];
return this.childNodes?.length > 0;
if (pos >= paths.length) {
const component = paths[pos];
if (component.name.startsWith("#") && pos < paths.length - 1) {
return this.searchNode(paths, pos + 1);
if (component.name === node.nodeName) {
if (component.pos === 0) {
const res = node.searchNode(paths, pos + 1);
} else if (stack.length === 0) {
const [parent] = stack.pop();
for (const child of parent.childNodes) {
if (component.name === child.nodeName) {
if (siblingPos === component.pos) {
return child.searchNode(paths, pos + 1);
return node.searchNode(paths, pos + 1);
if (node.childNodes?.length > 0) {
node = node.childNodes[0];
} else if (stack.length === 0) {
while (stack.length !== 0) {
const [parent, currentPos] = stack.pop();
const newPos = currentPos + 1;
if (newPos < parent.childNodes.length) {
stack.push([parent, newPos]);
node = parent.childNodes[newPos];
if (stack.length === 0) {
if (this.nodeName === "#text") {
buffer.push(encodeToXmlString(this.nodeValue));
buffer.push(`<${this.nodeName}`);
for (const attribute of this.attributes) {
buffer.push(` ${attribute.name}="${encodeToXmlString(attribute.value)}"`);
if (this.hasChildNodes()) {
for (const child of this.childNodes) {
buffer.push(`</${this.nodeName}>`);
} else if (this.nodeValue) {
buffer.push(`>${encodeToXmlString(this.nodeValue)}</${this.nodeName}>`);
class SimpleXMLParser extends XMLParserBase {
this._currentFragment = null;
this._errorCode = XMLParserErrorCode.NoError;
this._hasAttributes = hasAttributes;
this._lowerCaseName = lowerCaseName;
this._currentFragment = [];
this._errorCode = XMLParserErrorCode.NoError;
if (this._errorCode !== XMLParserErrorCode.NoError) {
const [documentElement] = this._currentFragment;
if (isWhitespaceString(text)) {
const node = new SimpleDOMNode("#text", text);
this._currentFragment.push(node);
const node = new SimpleDOMNode("#text", text);
this._currentFragment.push(node);
onBeginElement(name, attributes, isEmpty) {
if (this._lowerCaseName) {
name = name.toLowerCase();
const node = new SimpleDOMNode(name);
if (this._hasAttributes) {
node.attributes = attributes;
this._currentFragment.push(node);
this._stack.push(this._currentFragment);
this._currentFragment = node.childNodes;
this._currentFragment = this._stack.pop() || [];
const lastElement = this._currentFragment.at(-1);
for (const childNode of lastElement.childNodes) {
childNode.parentNode = lastElement;
;// CONCATENATED MODULE: ./src/core/metadata_parser.js
data = this._repair(data);
const parser = new SimpleXMLParser({
const xmlDocument = parser.parseFromString(data);
this._metadataMap = new Map();
this._parse(xmlDocument);
return data.replace(/^[^<]+/, "").replaceAll(/>\\376\\377([^<]+)/g, function (all, codes) {
const bytes = codes.replaceAll(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
}).replaceAll(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
throw new Error(`_repair: ${name} isn't defined.`);
for (let i = 0, ii = bytes.length; i < ii; i += 2) {
const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
charBuf.push(String.fromCharCode(code));
charBuf.push("&#x" + (0x10000 + code).toString(16).substring(1) + ";");
const name = entry.nodeName;
if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") {
return entry.childNodes.filter(node => node.nodeName === "rdf:li");
if (!entry.hasChildNodes()) {
const [seqNode] = entry.childNodes;
const sequence = this._getSequence(seqNode) || [];
this._metadataMap.set(entry.nodeName, sequence.map(node => node.textContent.trim()));
let rdf = xmlDocument.documentElement;
if (rdf.nodeName !== "rdf:rdf") {
while (rdf && rdf.nodeName !== "rdf:rdf") {
if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
for (const desc of rdf.childNodes) {
if (desc.nodeName !== "rdf:description") {
for (const entry of desc.childNodes) {
const name = entry.nodeName;
this._metadataMap.set(name, entry.textContent.trim());
parsedData: this._metadataMap,