Skip to content

Commit b874de1

Browse files
John Viegasjoviegas
John Viegas
authored andcommitted
XML entity encoding for carriage return and line feed
1 parent ea36ad8 commit b874de1

File tree

2 files changed

+24
-0
lines changed
  • core/protocols/aws-xml-protocol/src/main/java/software/amazon/awssdk/protocols/xml/internal/marshall
  • test/protocol-tests-core/src/main/resources/software/amazon/awssdk/protocol/suites/cases

2 files changed

+24
-0
lines changed

core/protocols/aws-xml-protocol/src/main/java/software/amazon/awssdk/protocols/xml/internal/marshall/XmlWriter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ private String escapeXmlEntities(String s) {
193193
s = s.replace("'", "'");
194194
s = s.replace("&lt;", "<");
195195
s = s.replace("&gt;", ">");
196+
s = s.replace("&#x0D;", "\r");
197+
s = s.replace("&#x0A;", "\n");
196198
// Ampersands should always be the last to unescape
197199
s = s.replace("&amp;", "&");
198200
}
@@ -202,6 +204,8 @@ private String escapeXmlEntities(String s) {
202204
s = s.replace("'", "&apos;");
203205
s = s.replace("<", "&lt;");
204206
s = s.replace(">", "&gt;");
207+
s = s.replace("\r", "&#x0D;");
208+
s = s.replace("\n", "&#x0A;");
205209
return s;
206210
}
207211

test/protocol-tests-core/src/main/resources/software/amazon/awssdk/protocol/suites/cases/rest-xml-input.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@
3838
}
3939
}
4040
},
41+
{
42+
"description": "Escape Characters are marshalled correctly as XML in the payload",
43+
"given": {
44+
45+
"input": {
46+
"stringMember": "\"'<\r\nNormalCharacters\"'>\r\n"
47+
}
48+
},
49+
"when": {
50+
"action": "marshall",
51+
"operation": "AllTypes"
52+
},
53+
"then": {
54+
"serializedAs": {
55+
"body": {
56+
"xmlEquals": "<AllTypesRequest xmlns=\"https://restxml/\"><stringMember>&quot;&apos;&lt;&#x0D;&#x0A;NormalCharacters&quot;&apos;&gt;&#x0D;&#x0A;</stringMember></AllTypesRequest>"
57+
}
58+
}
59+
}
60+
},
4161
{
4262
"description": "Boolean member with value true is marshalled correctly as XML",
4363
"given": {

0 commit comments

Comments
 (0)