From 753121825d32b34d6e577d34d46019974104b0ec Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Fri, 12 Jul 2019 19:21:36 +0100 Subject: [PATCH 1/2] XML: If text is completely white space don't add a text node Replicating behaviour of Foundation --- Sources/AWSSDKSwiftCore/XML.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/AWSSDKSwiftCore/XML.swift b/Sources/AWSSDKSwiftCore/XML.swift index 82a0d8bfa..64e0938a5 100644 --- a/Sources/AWSSDKSwiftCore/XML.swift +++ b/Sources/AWSSDKSwiftCore/XML.swift @@ -440,7 +440,10 @@ public class XML { } func parser(_ parser: XMLParser, foundCharacters: String) { - currentElement?.addChild(XML.Node.text(stringValue: foundCharacters)) + // if string with white space removed still has characters, add text node + if foundCharacters.components(separatedBy: .whitespaces).joined().count > 0 { + currentElement?.addChild(XML.Node.text(stringValue: foundCharacters)) + } } func parser(_ parser: XMLParser, foundComment comment: String) { From 3562b1f502d3509d09bc3887efbea9157dd71039 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Sat, 13 Jul 2019 10:27:03 +0100 Subject: [PATCH 2/2] Added whitespace test --- Tests/AWSSDKSwiftCoreTests/XMLTests.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/AWSSDKSwiftCoreTests/XMLTests.swift b/Tests/AWSSDKSwiftCoreTests/XMLTests.swift index 9ef8a2bc0..cc380011f 100644 --- a/Tests/AWSSDKSwiftCoreTests/XMLTests.swift +++ b/Tests/AWSSDKSwiftCoreTests/XMLTests.swift @@ -95,7 +95,18 @@ class XMLTests: XCTestCase { XCTFail(error.localizedDescription) } } - + + func testWhitespaceDecodeEncode() { + let xml = " before after " + do { + let xmlDocument = try XML.Document(data: xml.data(using: .utf8)!) + let xml2 = xmlDocument.xmlString + XCTAssertEqual(xml2, " beforeafter ") + } catch { + XCTFail(error.localizedDescription) + } + } + static var allTests : [(String, (XMLTests) -> () throws -> Void)] { return [ ("testAddChild", testAddChild),