Skip to content

Conversation

@mumoshu
Copy link
Contributor

@mumoshu mumoshu commented Feb 11, 2025

Fixes #643

This follows-up on #265 to fix how single-quoted strings are encoded.

That is, the only escape-sequence in a single-quoted string is now '' which represents ' literally.

Previously, it treated whatever starting with \ as a escape sequence, which is incorrect in a single-quoted string.
That resulted in encoding \. as \\. for example, which broke my use-case.
It's not YAML-compliant anyway so I believe making go-yaml compliant fixes my use-case too.


Before submitting your PR, please confirm the following.

  • Describe the purpose for which you created this PR.
    • See above
  • Create test code that corresponds to the modification
    • See the updated enmcoded_test.go
@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.55%. Comparing base (e6c495e) to head (4a2c1bb).
Report is 3 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #647      +/-   ##
==========================================
+ Coverage   77.29%   77.55%   +0.25%     
==========================================
  Files          22       22              
  Lines        7888     7841      -47     
==========================================
- Hits         6097     6081      -16     
+ Misses       1372     1347      -25     
+ Partials      419      413       -6     
encode_test.go Outdated
// In the YAML spec, the only escape sequence is '', which represents a single quote.
// \\, \n, \t, or whatever you might expect YAML, Go strings, and Go strconv.Quote() to escape using the extra backslash,
// are not escaped and printed as-is in the YAML single-quoted string.
"a: '\\.yaml'" + "\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is easier to understand.

`a: \.yaml` + "\n"

Also, since this behavior is self-explanatory, I felt that a comment was unnecessary. The current behavior seems to be an obvious bug in the UseSingleQuote option.

@goccy
Copy link
Owner

goccy commented Feb 11, 2025

Thank you for your great PR ! I've commented.

@mumoshu
Copy link
Contributor Author

mumoshu commented Feb 12, 2025

Thanks @goccy! Added 4a2c1bb

@yxxhero
Copy link

yxxhero commented Feb 12, 2025

@mumoshu @goccy cool. great PR.

@goccy
Copy link
Owner

goccy commented Feb 12, 2025

Thank you for your contribution !! LGTM 👍

@goccy goccy merged commit 13e918a into goccy:master Feb 12, 2025
20 checks passed
@mumoshu mumoshu deleted the use-single-quote-fix branch February 12, 2025 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants