Skip to content

Commit cb1f1ff

Browse files
authored
Add test for preserved spaces with xml entities (#234)
This test makes sure that strings containing xml entities surrounded with whitespaces are handled correctly.
1 parent de979e9 commit cb1f1ff

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Tests/XMLCoderTests/SpacePreserveTest.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ private let deCharacterXMLSpaced = """
4545
<t> \(deCharacterString) </t>
4646
""".data(using: .utf8)!
4747

48+
private let xmlEntityString = "one &amp; two"
49+
private let xmlEntityStringResult = "one & two"
50+
private let xmlEntityXml = """
51+
<t>\(xmlEntityString)</t>
52+
""".data(using: .utf8)!
53+
4854
private struct Item: Codable, Equatable {
4955
public let text: String?
5056

@@ -121,4 +127,11 @@ final class SpacePreserveTest: XCTestCase {
121127
XCTAssertEqual(resultGerman, " \(deCharacterString) ")
122128
}
123129

130+
func testXmlEntitesSpaced() throws {
131+
let decoder = XMLDecoder(trimValueWhitespaces: false)
132+
133+
let resultXmlEntity = try decoder.decode(String.self, from: xmlEntityXml)
134+
135+
XCTAssertEqual(resultXmlEntity, xmlEntityStringResult)
136+
}
124137
}

0 commit comments

Comments
 (0)