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

Text string '0x' is marshaled without quotes. #599

Open
mcdee opened this issue Dec 18, 2024 · 3 comments
Open

Text string '0x' is marshaled without quotes. #599

mcdee opened this issue Dec 18, 2024 · 3 comments
Labels
invalid This doesn't seem right

Comments

@mcdee
Copy link

mcdee commented Dec 18, 2024

Describe the bug

Attempting to marshal the text string '0x' returns without quotes.

To Reproduce

https://go.dev/play/p/Zu1JcjgLguZ

Expected behavior

The text string should be marshalled with quotes, as it is a string.

Version Variables

  • Go version: 1.21
  • go-yaml's Version: e.g. v1.15.11
@mcdee mcdee added the bug Something isn't working label Dec 18, 2024
@goccy
Copy link
Owner

goccy commented Dec 19, 2024

@mcdee This is not a bug. First, flow mode is not JSON. Additionally, '0x' is correctly interpreted as a string, so when the output is unmarshalled, it will be treated as a string. If you're expecting JSON, you should use yaml.YAMLToJSON

@goccy goccy added invalid This doesn't seem right and removed bug Something isn't working labels Dec 19, 2024
@mcdee
Copy link
Author

mcdee commented Dec 19, 2024

Is there an option to output anything that is a Go string as a quoted value in go-yaml? The change to behavior (this value was output quoted prior to 1.13.16) is causing broken tests in our repos, but we don't control the source data for the tests (round trip unmarshal and marshal) so we can't work around it easily.

@goccy
Copy link
Owner

goccy commented Dec 19, 2024

@mcdee Basically, quotes are added only to values that cannot be interpreted as strings. Therefore, since '0x' is clearly a string, quotes cannot be added. Currently, there is no option to explicitly add quotes to strings, so implementing such a feature would require new development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants