Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump fast-xml-parser to 4.0.11 #599

Merged
merged 4 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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