Skip to content

Commit

Permalink
Fix CDATA issue (CoreOffice#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov authored and Arjun Gupta committed Jun 26, 2020
1 parent 495aff9 commit 017c17d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/XMLCoder/Auxiliaries/Box/KeyedBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct KeyedBox {
}

var value: SimpleBox? {
return elements[""].first as? SimpleBox
return elements.values.first as? SimpleBox
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/XMLCoder/Auxiliaries/KeyedStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ struct KeyedStorage<Key: Hashable & Comparable, Value> {
return buffer.map { $0.0 }
}

var values: [Value] {
return buffer.map { $0.1 }
}

init<S>(_ sequence: S) where S: Sequence, S.Element == (Key, Value) {
buffer = Buffer()
keyMap = KeyMap()
Expand Down
28 changes: 28 additions & 0 deletions Tests/XMLCoderTests/CDATATest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by Max Desiatov on 09/04/2020.
//

import XCTest
import XMLCoder

private struct Container: Codable, Equatable {
let value: Int
let data: String
}

private let xml =
"""
<container>
<value>42</value>
<data><![CDATA[lorem ipsum]]></data>
</container>
""".data(using: .utf8)!

final class CDATATest: XCTestCase {
func testXML() throws {
let decoder = XMLDecoder()
let result = try decoder.decode(Container.self, from: xml)

XCTAssertEqual(result, Container(value: 42, data: "lorem ipsum"))
}
}

0 comments on commit 017c17d

Please sign in to comment.