Repository navigation
fix: quote YAML 1.1 ambiguous strings - #202
Vasundhara117 wants to merge 1 commit into
Conversation
anurag629
left a comment
There was a problem hiding this comment.
Thanks @Vasundhara117, this is close. Everything listed in #145 is quoted now, and the ones that should stay bare still are. I ran all of them through PyYAML 6.0, js-yaml and yaml in 1.1 mode, as values and as keys, and each one comes back as the same string. On top of develop, lint, all 381 tests and the build pass, the new tests fail on develop's json-utils.ts, and taking out any one of your new checks fails a test.
One gap, partly my fault for writing "between the digits" in the issue. YAML 1.1 parsers take _ anywhere after the first digit, and a base 60 number can end in a dot, so PyYAML still reads these back as numbers (yaml in 1.1 mode too):
1__000and1000_give10001.0_0gives1.0, and.5_0gives0.50b_101and0b101_give51_0:30gives630, and1:30.gives90.0
Your hex check already allows _ anywhere after 0x. Could you do the same in the decimal, binary and base 60 checks, and add these to the quoted list in the test? _1, 0b2 and the other bare ones should stay as they are.
Small thing while you're in there: the extra blank line at line 155 of the test file can go.
What and why
Quote strings that YAML 1.1 parsers may interpret as numbers, booleans, timestamps, or merge-key syntax. Add regression tests for the specified edge cases while preserving unquoted output for ordinary strings.
Closes #145
How I tested this
npx vitest run lib/__tests__/json-utils.test.ts— passednpm run lint— 0 errors; 13 warnings in existing, unrelated filesnpm run test— 381 tests passednpm run build— passedAI assistance
Used ChatGPT to help interpret the issue requirements, reason through edge cases, and review the implementation and tests.
Type of change
Checklist
npm run lint && npm run test && npm run buildpasses locallylib/and have a test inlib/__tests__/page.tsx, client component,opengraph-image.tsx, and the bug report dropdown are all doneNotes for reviewers
The tests verify YAML output text directly without adding a YAML parser dependency.