Skip to content

Commit

Permalink
Fix CDATA issue
Browse files Browse the repository at this point in the history
Resolves #168
  • Loading branch information
MaxDesiatov committed Apr 9, 2020
1 parent 37f87d9 commit bfda0ae
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
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
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
@@ -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 bfda0ae

Please sign in to comment.