Skip to content
New issue

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

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

Already on GitHub? # to your account

(yaml) Empty string serialized without quotes if MINIMIZE_QUOTES is enabled #50

Closed
tim-palmer opened this issue Nov 3, 2017 · 6 comments
Labels
yaml Issue related to YAML format backend
Milestone

Comments

@tim-palmer
Copy link

tim-palmer commented Nov 3, 2017

YAMLGenerator does not quote empty strings if MINIMIZE_QUOTES is enabled.

The YAML 1.2 spec says that plain (unquoted) scalars cannot be empty i.e. an empty string must always be quoted.

      YAMLFactory f = new YAMLFactory();
      f.configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true);

      YAMLMapper mapper = new YAMLMapper(f);

      Map<String, Object> content = new HashMap<>();
      content.put("key", "");
      String yaml = mapper.writeValueAsString(content).trim();

      assertEquals("---\nkey: \"\"", yaml); // fails - actual output is "---\nkey:"
@cowtowncoder
Copy link
Member

That sounds like SnakeYAML problem, since it is used for generation.
Is this with the latest version? (2.9.2)

@cowtowncoder cowtowncoder added enhancement yaml Issue related to YAML format backend and removed enhancement labels Nov 3, 2017
@tim-palmer
Copy link
Author

Yes - I am using 2.8.9 but I can also reproduce the issue with 2.9.2.

@cowtowncoder
Copy link
Member

Fwtw, looks like there is one more release of SnakeYAML, 1.19:

https://bitbucket.org/asomov/snakeyaml/wiki/Changes

which could have a relevant fix. I did not see any issue that seemed related, but I can test locally.

cowtowncoder added a commit that referenced this issue Nov 6, 2017
…keYAML does not help with the problem
@cowtowncoder
Copy link
Member

Added a failing tests, reproduces with 2.9, 3.0.0-SNAPSHOT. Newer version of SnakeYAML does not make difference here.

@asomov
Copy link
Contributor

asomov commented Mar 8, 2018

You mention YAML 1.2 spec.

SnakeYAML supports YAML 1.1

@cowtowncoder
Copy link
Member

@asomov Ah. Good point, I added explicit mention of 1.2 in description.

I wonder if forced quoting might be useful, still, even without requiring 1.2 compliancy.

@cowtowncoder cowtowncoder added 2.10 and removed active labels Jun 1, 2019
@cowtowncoder cowtowncoder added this to the 2.10.0 milestone Jun 1, 2019
cowtowncoder added a commit that referenced this issue Jun 1, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

3 participants