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

Coorce empty map values to null #35

Open
dergachev opened this issue Aug 5, 2014 · 5 comments
Open

Coorce empty map values to null #35

dergachev opened this issue Aug 5, 2014 · 5 comments

Comments

@dergachev
Copy link

I'm not a yaml expert, but it seems that there might be a bug in handling of empty map values, eg:


---
1: a
2: 

Here's how spyc handles it when there's tilde (by correctly print NULL):

INPUT: 

---
1: a
2: ~

RESULT:

array(2) {
  [1]=>
  string(1) "a"
  [2]=>
  NULL
}

Here's how spyc handles empty map value, should print NULL, prints empty string:

INPUT:

---
1: a
2:

RESULT:

array(2) {
  [1]=>
  string(1) "a"
  [2]=>
  string(0) ""
}

php source code: https://gist.github.com/dergachev/c2b3c18d65edf00aa8fd

I haven't read the yaml spec, I'm quite sure libyaml behaves differently.
And here's a random stack overflow thread that seems to confirm it:
http://stackoverflow.com/questions/833927/yaml-dictionary-with-empty-value

@dergachev
Copy link
Author

Potentially related:
#20
e1d6159

@dergachev
Copy link
Author

Sorry had typos in original bug description. Fixed now, let me know if it's not clear.

@jackmcdade
Copy link
Collaborator

The 1.0 spec is totally ambiguous when it comes to handling an empty map value. There simply is zero mention of it in the entire document. In 1.1 they add the addition of ~ or "empty". I feel like it's a logical solution, since a strict type is more useful than an empty string, but with Spyc behaving this way for so long I'm not sure it's worth changing the behavior as I'm fairly certain any application still relying on it (mine included) as accounted for it.

I would say this is not a bug, but still open to consensus as to how to treat it. And i know this is an old issue. But I'm trying to bring Spyc up to modern glory, since I rely on it every day with Statamic.

@jackmcdade jackmcdade changed the title Bug in handling of empty dictionary values Coorce empty map values to null Oct 20, 2016
@christhomas
Copy link

christhomas commented Nov 28, 2016

well for example an empty map should be read from the yaml into an empty map and then written back to the file as an empty map.

but if I try this, my empty map is turned into an empty string, which when written back, is an empty string.

the correct result is, that they should remain the same, you should not be able to see any difference.

so either we need a way to tell spyc to do that cause right now it does not, or consider this a bug (which I think it is) then wonder how to fix it.

input file --> read into variable, immediately write into --> output file

there should be no functional difference between input file and output file.

@jackmcdade
Copy link
Collaborator

jackmcdade commented Nov 28, 2016 via email

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