Skip to content

Commit

Permalink
Merge pull request #344 from mxsph/update-fast-xml-parser
Browse files Browse the repository at this point in the history
chore(deps): update fast-xml-parser to 4.2.4
  • Loading branch information
perry-mitchell committed Jun 18, 2023
2 parents 0317b36 + f52d7d4 commit 229f185
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
34 changes: 20 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@buttercup/fetch": "^0.1.1",
"base-64": "^1.0.0",
"byte-length": "^1.0.2",
"fast-xml-parser": "^3.19.0",
"fast-xml-parser": "^4.2.4",
"he": "^1.2.0",
"hot-patcher": "^2.0.0",
"layerr": "^0.1.2",
Expand Down
26 changes: 16 additions & 10 deletions source/tools/dav.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path-posix";
import xmlParser from "fast-xml-parser";
import { XMLParser } from "fast-xml-parser";
import nestedProp from "nested-property";
import { decodeHTMLEntities } from "./encode.js";
import { normalisePath } from "./path.js";
Expand Down Expand Up @@ -72,17 +72,23 @@ function normaliseResult(result: DAVResultRaw): DAVResult {
return output as DAVResult;
}

function getParser(): XMLParser {
return new XMLParser({
removeNSPrefix: true,
numberParseOptions: {
hex: true,
leadingZeros: false
}
// // We don't use the processors here as decoding is done manually
// // later on - decoding early would break some path checks.
// attributeValueProcessor: val => decodeHTMLEntities(decodeURIComponent(val)),
// tagValueProcessor: val => decodeHTMLEntities(decodeURIComponent(val))
});
}

export function parseXML(xml: string): Promise<DAVResult> {
return new Promise(resolve => {
const result = xmlParser.parse(xml, {
arrayMode: false,
ignoreNameSpace: true,
parseTrueNumberOnly: true
// // We don't use the processors here as decoding is done manually
// // later on - decoding early would break some path checks.
// attrValueProcessor: val => decodeHTMLEntities(decodeURIComponent(val)),
// tagValueProcessor: val => decodeHTMLEntities(decodeURIComponent(val))
});
const result = getParser().parse(xml);
resolve(normaliseResult(result));
});
}
Expand Down
25 changes: 14 additions & 11 deletions source/tools/xml.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import xmlParser, { j2xParser as XMLParser } from "fast-xml-parser";
import { XMLParser, XMLBuilder } from "fast-xml-parser";

type NamespaceObject = { [key: string]: any };

export function generateLockXML(ownerHREF: string): string {
return getParser().parse(
return getBuilder().build(
namespace(
{
lockinfo: {
Expand All @@ -24,12 +24,20 @@ export function generateLockXML(ownerHREF: string): string {
);
}

function getParser(): XMLParser {
return new XMLParser({
function getBuilder(): XMLBuilder {
return new XMLBuilder({
attributeNamePrefix: "@_",
format: true,
ignoreAttributes: false,
supressEmptyNode: true
suppressEmptyNode: true
});
}

function getParser(): XMLParser {
return new XMLParser({
removeNSPrefix: true,
parseAttributeValue: true,
parseTagValue: true
});
}

Expand All @@ -51,10 +59,5 @@ function namespace<T extends NamespaceObject>(obj: T, ns: string): T {
}

export function parseGenericResponse(xml: string): Object {
return xmlParser.parse(xml, {
arrayMode: false,
ignoreNameSpace: true,
parseAttributeValue: true,
parseNodeValue: true
});
return getParser().parse(xml);
}

0 comments on commit 229f185

Please sign in to comment.