fix(yaml): quote leading-zero integer-shaped strings in stringify#7164
Open
LeSingh1 wants to merge 1 commit into
Open
fix(yaml): quote leading-zero integer-shaped strings in stringify#7164LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
resolveYamlInteger accepts "07" as octal so stringify already quoted
it, but "08" and "09" fell through because they aren't valid octal.
They still read as numbers to humans and to other YAML parsers though,
so they need to be quoted too.
Force-quote any string matching /^[-+]?0[0-9]+$/ to cover the
non-octal leading-zero cases ("08", "09", "089", "-012", ...).
Fixes denoland#7040
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7164 +/- ##
==========================================
- Coverage 94.57% 94.57% -0.01%
==========================================
Files 636 636
Lines 52142 52144 +2
Branches 9401 9402 +1
==========================================
+ Hits 49315 49316 +1
Misses 2249 2249
- Partials 578 579 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7040.
resolveYamlInteger accepts "07" as octal so stringify already quoted it, but "08" and "09" fell through because they aren't valid octal:
These still read as numbers to humans and to other YAML parsers, so they should be quoted too. The fix adds a
/^[-+]?0[0-9]+$/guard inchooseScalarStyleso any integer-shaped string with a leading zero forces single-quoted style. After the patch:Tests added in
yaml/stringify_test.tscover the issue cases plus edge cases (signed, mixed digits, non-integer-shaped strings).