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

Non-string values are being encoded as CData when stringEncodingStrategy = .cdata #178

Closed
ksoftllc opened this issue May 1, 2020 · 3 comments · Fixed by #179
Closed
Assignees
Labels
bug Something isn't working

Comments

@ksoftllc
Copy link

ksoftllc commented May 1, 2020

Example:

import Foundation
import XMLCoder

struct CData: Codable {
    let string: String
    let int: Int
    let bool: Bool
}

let example = CData(string: "string", int: 123, bool: true)
let xmlEncoder = XMLEncoder()
xmlEncoder.stringEncodingStrategy = .cdata
xmlEncoder.outputFormatting = .prettyPrinted
let encoded = xmlEncoder.encode(example)
let encodedAsString = String(data: encoded, encoding: .utf8)
print(encodedAsString!)

Produces:

<CData>
    <string><![CDATA[string]]></string>
    <int><![CDATA[123]]></int>
    <bool><![CDATA[true]]></bool>
</CData>

Expected:

<CData>
    <string><![CDATA[string]]></string>
    <int>123</int>
    <bool>true</bool>
</CData>
@MaxDesiatov MaxDesiatov self-assigned this May 1, 2020
@MaxDesiatov MaxDesiatov added the bug Something isn't working label May 1, 2020
@MaxDesiatov
Copy link
Collaborator

Thanks for reporting this @ksoftllc, I'll have a look.

@MaxDesiatov
Copy link
Collaborator

@ksoftllc this is now fixed in master and will be released as a part of 0.11.1. Thanks again!

@ksoftllc
Copy link
Author

ksoftllc commented May 3, 2020

Thank you. Nice library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants