Skip to content

Commit

Permalink
Bump fast-xml-parser to 4.0.11 (#599)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
  • Loading branch information
AllanZhengYP and trivikr committed Oct 11, 2022
1 parent 88b4e8e commit d75d96d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private String registerBodyComparatorStub(String mediaType) {
case "application/xml":
writer.addDependency(TypeScriptDependency.XML_PARSER);
writer.addDependency(TypeScriptDependency.HTML_ENTITIES);
writer.addImport("parse", "xmlParse", "fast-xml-parser");
writer.addImport("XMLParser", null, "fast-xml-parser");
writer.addImport("decodeHTML", "decodeHTML", "entities");
additionalStubs.add("protocol-test-xml-stub.ts");
return "compareEquivalentXmlBodies(bodyString, r.body.toString())";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package software.amazon.smithy.typescript.codegen;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -98,7 +97,7 @@ public enum TypeScriptDependency implements SymbolDependencyContainer {
AWS_SDK_QUERYSTRING_BUILDER("dependencies", "@aws-sdk/querystring-builder", false),

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

// Server dependency for SSDKs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ const compareEquivalentXmlBodies = (
): Object => {
const parseConfig = {
attributeNamePrefix: "",
htmlEntities: true,
ignoreAttributes: false,
parseNodeValue: false,
ignoreDeclaration: true,
parseTagValue: false,
trimValues: false,
tagValueProcessor: (val: any, tagName: any) =>
val.trim() === "" ? "" : decodeHTML(val),
tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
};

const parseXmlBody = (body: string) => {
const parsedObj = xmlParse(body, parseConfig);
const parser = new XMLParser(parseConfig);
parser.addEntity("#xD", "\r");
parser.addEntity("#10", "\n");
const parsedObj = parser.parse(body);
const textNodeName = "#text";
const key = Object.keys(parsedObj)[0];
const parsedObjToReturn = parsedObj[key];
Expand Down

0 comments on commit d75d96d

Please sign in to comment.