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

Empty string parsed as <null> #53

Closed
yonaskolb opened this issue Aug 26, 2017 · 4 comments
Closed

Empty string parsed as <null> #53

yonaskolb opened this issue Aug 26, 2017 · 4 comments

Comments

@yonaskolb
Copy link

If you try to specify an empty string as a value it's parsed as <null> instead of an empty string

yaml file:

string1: "string"
string2: string
emptyString: ""
let string = getFile()
let yaml = try Yams.load(yaml: string)
let dictionary = yaml as! [String: Any]
print(dictionary["emptyString"]!) // prints "<null>" instead of ""
@norio-nomura
Copy link
Collaborator

This is expected behavior with using Resolver.default.
https://github.com/jpsim/Yams/blob/master/Tests/YamsTests/ResolverTests.swift#L61
Please try using Resolver.basic as following:

let yaml = try Yams.load(yaml: string, .basic)
let dictionary = yaml as! [String: Any]
print(dictionary["emptyString"]!) // "\n"

@yonaskolb
Copy link
Author

I see. If I used the basic Resolver I'd miss out on a lot of extra things though. It seems to me that default is supposed to be yaml defaults while basic providers some helpers. Wouldn't "" being parsed as an empty string be helpful? Is there any other way to represent an empty string?

@norio-nomura
Copy link
Collaborator

Currently, since Resolver.init is not disclosed, customized Resolver can not be created.
Similar problems are solved by creating customized Constructor in SwiftLint.
https://github.com/realm/SwiftLint/pull/1703/files#diff-eed8e78a3af97adda7152e3a5ff4c93eR31

@jpsim
Copy link
Owner

jpsim commented Nov 3, 2017

This should now be doable via Resolver.Rule added in #66.

@jpsim jpsim closed this as completed Nov 3, 2017
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

No branches or pull requests

3 participants