Fix #701: quote YAML 1.1 number-form Strings under ALWAYS_QUOTE_NUMBERS_AS_STRINGS - #705
Merged
cowtowncoder merged 4 commits intoJul 24, 2026
Conversation
Member
|
Could this be re-created against |
…OTE_NUMBERS_AS_STRINGS PLAIN_NUMBER_P did not match exponent (1e5), hex (0x1F) or underscore (12_34) forms, so those Strings were emitted unquoted and silently re-read as numbers. Also match against SnakeYAML's own int/float resolver patterns so every String that would resolve to a number is quoted and round-trips.
seonwooj0810
force-pushed
the
fix/issue-701-minimize-quotes-number-forms
branch
from
July 23, 2026 13:08
8f15717 to
936f10f
Compare
Contributor
Author
|
Done — rebased the fix onto |
cowtowncoder
approved these changes
Jul 24, 2026
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 #701
Root cause
With
MINIMIZE_QUOTES+ALWAYS_QUOTE_NUMBERS_AS_STRINGSenabled,YAMLGenerator.writeStringdecides whether a String must be quoted by matching it againstPLAIN_NUMBER_P([+-]?[0-9]*(\.[0-9]*)?). That regex only recognizes plain decimal integers/floats, so YAML 1.1 number forms it does not match — exponent (1e5), hex (0x1F), underscore (12_34) — were emitted unquoted. SnakeYAML (and every other YAML reader) then resolves those plain scalars back to numbers, so the value silently changes on a read/write cycle ("1e5"->100000.0). The feature is documented to keep number-like Strings distinguishable, but its detection was incomplete.Change
Detection now also matches SnakeYAML's own implicit
int/floatresolver patterns (Resolver.INT/Resolver.FLOAT) — the exact patterns the parser uses to resolve plain scalars — in addition to the historicalPLAIN_NUMBER_P(kept, so existing output is a strict superset and no previously-quoted value becomes unquoted). Any String that would resolve to a number is therefore quoted and round-trips. Scoped to the opt-inALWAYS_QUOTE_NUMBERS_AS_STRINGSpath; defaultMINIMIZE_QUOTESoutput is unchanged.Test evidence
Added
GeneratorWithMinimizeTest.testQuoteYAML11NumberFormsStoredAsString701: asserts1e5,0x1F,12_34,1.5e-3,0b101are now quoted and round-trip throughreadTree, while a genuine non-number version String (2.0.1.2.3) stays unquoted. The test fails before this change (1e5emitted askey: 1e5) and passes after.Verification done: full
yamlmodule suite green (./mvnw -pl yaml test— 168 tests, 0 failures), including the pre-existingALWAYS_QUOTE_NUMBERS_AS_STRINGStests; the new test confirmed red-before/green-after.