diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java index 9263b51d7ab..def9d9907b5 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java @@ -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())"; diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java index 7afb9ad2ee9..9112153ff99 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDependency.java @@ -15,7 +15,6 @@ package software.amazon.smithy.typescript.codegen; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -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 diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-xml-stub.ts b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-xml-stub.ts index f38c0ed58d2..626fab5adcb 100644 --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-xml-stub.ts +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-xml-stub.ts @@ -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];