JSON to YAML: control characters are written raw, so PyYAML and js-yaml can't read the output
I maintainer di solito rispondono entro 1 giorno
@anurag2787 ci sta già lavorando.
Dal 21/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
The JSON formatter's YAML conversion (toYAML in lib/json-utils.ts) copies control characters into the output as they are. This JSON
{"soh":"\u0001","bell":"a\u0007b"}
gives the following, where <U+0001> and <U+0007> stand for the raw characters:
soh: <U+0001>
bell: a<U+0007>b
PyYAML stops with ReaderError: unacceptable character #x0001: special characters are not allowed, and js-yaml with the stream contains non-printable characters. (The yaml package on npm does read it.) The likeliest real case is log output with ANSI color codes, like {"log":"\u001b[31mred\u001b[0m"}.
The same happens with:
- the rest of U+0000 to U+001F, except tab, line feed and carriage return
- U+007F (DEL), and U+0080 to U+009F apart from U+0085
- U+FFFE and U+FFFF
U+0085 (NEL), U+2028 and U+2029 are line breaks in YAML 1.1. PyYAML sees {"v":"a\u2028b"} (written as v: a<U+2028>b) as a value cut off by a new line and fails with could not find expected ':', and inside double quotes it drops a NEL: {"v":"a: \u0085b"} comes back as a: b.
Checked with js-yaml 4.3, yaml 2.9 and PyYAML 6.0.
needsQuote only forces quotes for \n, \t, \r and " (line 364), and yamlString only escapes \, ", \n, \t and \r (line 371). Keys go through yamlString too, so {"a\u0001b":1} breaks the same way.
What to do
- Quote a string when it contains any of the characters above: U+0000 to U+001F other than tab, LF and CR, U+007F to U+009F, U+2028, U+2029, U+FFFE and U+FFFF.
- Inside the double quotes, escape them as
\xNNbelow U+0100 and\uNNNNabove it, with uppercase hex (\x1B, not\x1b). YAML 1.1 and 1.2 both have these escapes. Do it after the existing backslash replace, so the new backslashes don't get doubled. - Keep the
\n,\tand\rescapes as they are.
Where to look
lib/json-utils.ts:needsQuote(line 348, the check at line 364) andyamlString(line 369, the escapes at line 371)lib/__tests__/json-utils.test.ts: thetoYAMLtests (line 244)- #237 (exponent numbers in JSON to YAML) changes
yamlValue(line 375) in the same file. The two changes don't overlap, but whoever merges second may need to rebase.
Acceptance criteria
-
{"soh":"\u0001","bell":"a\u0007b"}givessoh: "\x01"andbell: "a\x07b" -
{"log":"\u001b[31mred\u001b[0m"}giveslog: "\x1B[31mred\x1B[0m" - U+0000, U+007F, U+0080, U+0085 and U+009F come out as
\x00,\x7F,\x80,\x85and\x9F, and U+2028, U+2029 and U+FFFE as\u2028,\u2029and\uFFFE - Keys are escaped too:
{"a\u0001b":1}gives"a\x01b": 1 -
{"v":"x\ty\nz"}still givesv: "x\ty\nz", and strings without these characters don't change - Tests check the output text for these cases (please don't add a YAML parser as a dependency)
-
npm run lint,npm run testandnpm run buildpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #234 in the description.
- Lingua principale
- TypeScript
- Stelle
- 1
- Fork
- 9
- Merge medio
- 9h 50m
- PR unite (30g)
- 105
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di codercops/toolbelt
-
JSONPath: big numbers in the results are roundedForse già presa @arxh80 l’ha presa 1 giorno fa. Apertabug hacktoberfest help wanted
Difficoltà 3/5 1-2 giorni Idoneità per principianti 78/100
codercops/toolbelt#238 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Color converter: the contrast ratio shows `4.50 : 1` while Normal AA says FAILForse già presa @bercedev l’ha presa 1 giorno fa. Apertabug good first issue hacktoberfest
codercops/toolbelt#235 · 5 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
JSON formatter: Escape for code gives broken Python when the text has a run of single quotesForse già presa @anurag2787 l’ha presa 1 giorno fa. Apertabug good first issue hacktoberfest
codercops/toolbelt#233 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Add the URL encoder to the README, the home share card and package.jsonForse già presa @Abhishek764 l’ha presa 3 giorni fa. Apertadocumentation good first issue hacktoberfest
codercops/toolbelt#153 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue hacktoberfest new tool
codercops/toolbelt#128 · 9 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di codercops/toolbelt
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
maniator/verticopolis#1303 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
components-web-app/docs#297 ·
-
listFeatures/getFeatureExamples never return Kotlin examples for Android or server Kotlin SDKsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
appwrite/mcp-for-docs#23 · 1 commento ·
-
`@vanilla-extract/turbopack-plugin`: "getImageSize is not a function" with Next.js 16.4.x when a `.css.ts` file imports an imageForse già presa @aevarOrigo l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vanilla-extract-css/vanilla-extract#1799 · 1 commento ·
-
native
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
prime-radiant-inc/evener#4839 ·
I maintainer di solito rispondono entro 1 giorno