Skip to content

Commit 0325642

Browse files
AllanZhengYPtrivikr
authored andcommitted
Bump fast-xml-parser to 4.0.11 (smithy-lang#599)
Co-authored-by: Kamat, Trivikram <[email protected]>
1 parent d5e294e commit 0325642

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ private String registerBodyComparatorStub(String mediaType) {
575575
case "application/xml":
576576
writer.addDependency(TypeScriptDependency.XML_PARSER);
577577
writer.addDependency(TypeScriptDependency.HTML_ENTITIES);
578-
writer.addImport("parse", "xmlParse", "fast-xml-parser");
578+
writer.addImport("XMLParser", null, "fast-xml-parser");
579579
writer.addImport("decodeHTML", "decodeHTML", "entities");
580580
additionalStubs.add("protocol-test-xml-stub.ts");
581581
return "compareEquivalentXmlBodies(bodyString, r.body.toString())";

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package software.amazon.smithy.typescript.codegen;
1717

18-
1918
import java.io.BufferedReader;
2019
import java.io.IOException;
2120
import java.io.InputStreamReader;
@@ -98,7 +97,7 @@ public enum TypeScriptDependency implements SymbolDependencyContainer {
9897
AWS_SDK_QUERYSTRING_BUILDER("dependencies", "@aws-sdk/querystring-builder", false),
9998

10099
// Conditionally added when XML parser needs to be used.
101-
XML_PARSER("dependencies", "fast-xml-parser", "3.19.0", false),
100+
XML_PARSER("dependencies", "fast-xml-parser", "4.0.11", false),
102101
HTML_ENTITIES("dependencies", "entities", "2.2.0", false),
103102

104103
// Server dependency for SSDKs

smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-xml-stub.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ const compareEquivalentXmlBodies = (
88
): Object => {
99
const parseConfig = {
1010
attributeNamePrefix: "",
11+
htmlEntities: true,
1112
ignoreAttributes: false,
12-
parseNodeValue: false,
13+
ignoreDeclaration: true,
14+
parseTagValue: false,
1315
trimValues: false,
14-
tagValueProcessor: (val: any, tagName: any) =>
15-
val.trim() === "" ? "" : decodeHTML(val),
16+
tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
1617
};
1718

1819
const parseXmlBody = (body: string) => {
19-
const parsedObj = xmlParse(body, parseConfig);
20+
const parser = new XMLParser(parseConfig);
21+
parser.addEntity("#xD", "\r");
22+
parser.addEntity("#10", "\n");
23+
const parsedObj = parser.parse(body);
2024
const textNodeName = "#text";
2125
const key = Object.keys(parsedObj)[0];
2226
const parsedObjToReturn = parsedObj[key];

0 commit comments

Comments
 (0)