Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDATA usage in array of tags gives empty string instead of value #260

Closed
johankool opened this issue Mar 15, 2023 · 0 comments · Fixed by #261
Closed

CDATA usage in array of tags gives empty string instead of value #260

johankool opened this issue Mar 15, 2023 · 0 comments · Fixed by #261

Comments

@johankool
Copy link
Contributor

johankool commented Mar 15, 2023

I am trying to get this failing test to work, but not getting anywhere.

import XCTest
import XMLCoder

final class CDATAEntryTest: XCTestCase {
    private struct DataEntry: Codable, Equatable {
        let value: String
        enum CodingKeys: String, CodingKey {
            case value = ""
        }
    }
    
    private struct Container: Codable, Equatable {
        let data: [DataEntry]
    }
    
    private let xml =
        """
        <container>
           <data><![CDATA[lorem ipsum]]></data>
           <data>bla bla</data>
        </container>
        """.data(using: .utf8)!
    
    func testXMLWithCDataDataEntries() throws {
        let decoder = XMLDecoder()
        let result = try decoder.decode(Container.self, from: xml)
        XCTAssertEqual(result, Container(data: [.init(value: "lorem ipsum"), .init(value: "bla bla")])) // FAILS: got: ["", "bla bla"], but expected: ["lorem ipsum", "bla bla"]
    }
}
johankool added a commit to egeniq-forks/XMLCoder that referenced this issue Mar 15, 2023
johankool added a commit to egeniq-forks/XMLCoder that referenced this issue Mar 15, 2023
Joannis pushed a commit that referenced this issue Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant