Skip to content

Commit c6296b9

Browse files
committed
fix: call he from protocol-test-xml-stub
1 parent 09b6a44 commit c6296b9

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ private String registerBodyComparatorStub(String mediaType) {
459459
return "compareEquivalentJsonBodies(bodyString, r.body.toString())";
460460
case "application/xml":
461461
writer.addDependency(TypeScriptDependency.XML_PARSER);
462+
writer.addDependency(TypeScriptDependency.HTML_ENTITIES);
462463
writer.addImport("parse", "xmlParse", "fast-xml-parser");
464+
writer.addImport("decode", "heDecode", "he");
463465
additionalStubs.add("protocol-test-xml-stub.ts");
464466
return "compareEquivalentXmlBodies(bodyString, r.body.toString())";
465467
case "application/octet-stream":

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22
* Returns a map of key names that were un-equal to value objects showing the
33
* discrepancies between the components.
44
*/
5-
const compareEquivalentXmlBodies = (expectedBody: string, generatedBody: string): Object => {
6-
const decodeEscapedXml = (str: string) => {
7-
return str
8-
.replace(/&/g, "&")
9-
.replace(/'/g, "'")
10-
.replace(/"/g, '"')
11-
.replace(/>/g, ">")
12-
.replace(/&lt;/g, "<");
13-
};
14-
5+
const compareEquivalentXmlBodies = (
6+
expectedBody: string,
7+
generatedBody: string
8+
): Object => {
159
const parseConfig = {
16-
attributeNamePrefix: '',
10+
attributeNamePrefix: "",
1711
ignoreAttributes: false,
1812
parseNodeValue: false,
1913
trimValues: false,
20-
tagValueProcessor: (val: any, tagName: any) => val.trim() === "" ? "" : decodeEscapedXml(val)
14+
tagValueProcessor: (val: any, tagName: any) =>
15+
val.trim() === "" ? "" : heDecode(val),
2116
};
2217

2318
const parseXmlBody = (body: string) => {
@@ -36,4 +31,4 @@ const compareEquivalentXmlBodies = (expectedBody: string, generatedBody: string)
3631
const generatedParts = parseXmlBody(generatedBody);
3732

3833
return compareParts(expectedParts, generatedParts);
39-
}
34+
};

0 commit comments

Comments
 (0)