JSON formatter: Escape for code gives broken Python when the text has a run of single quotes
Los mantenedores suelen responder en 1 día
@anurag2787 ya está trabajando en esto.
Desde el 21/10/2026.
- #243 de @ElectLive — cerrado sin fusionar
Evaluación
Este issue todavía no se ha evaluado.
Descripción
In the JSON formatter, open "Conversions · Validate · Query", pick "Escape for code" and set the target language to Python. With this JSON:
{"a":"'''''"}
the output is
'''{"a":"'\''''"}'''
and Python 3.10 rejects it:
SyntaxError: unterminated string literal (detected at line 1)
escapeForCode (lib/json-utils.ts, line 677) wraps the JSON in '''...''' and only handles runs of three quotes, by turning each ''' into '\'' (line 691). With five quotes, the two that are left over join the last ' of the replacement and make a new ''', which closes the string early. Eight quotes in a row break it the same way.
When the input isn't valid JSON, the function escapes the raw text instead (line 682), and that breaks whenever the text ends in a quote: it's' gives '''it's'''', where Python closes the string after it's and then finds a lone '.
Double quotes are fine. JSON already escapes them as \", and the backslash pass doubles the backslash.
What to do
- After the backslash pass, escape every single quote (
.replace(/'/g, "\\'")) instead of only'''. Inside'''...''',\'is always a plain quote, so the string can't close early. - Keep the backslash pass first, so the new backslashes don't get doubled.
- The other languages stay as they are.
Where to look
lib/json-utils.ts:escapeForCode(line 677) and its Python branch (line 691)lib/__tests__/json-utils.test.ts: theescapeForCode pythontests (line 214)app/(tools)/json-formatter/components/ConversionPanel.tsx: the language list (line 32) and the Escape for code mode (line 62), if you want to try it in the UI
Acceptance criteria
-
{"a":"'''''"}gives'''{"a":"\'\'\'\'\'"}''' -
{"a":"''''''''"}(eight quotes) gives'''{"a":"\'\'\'\'\'\'\'\'"}''' -
it's'gives'''it\'s\'''' - The existing backslash test still passes:
{"path":"C:\\temp"}gives'''{"path":"C:\\\\temp"}''' - Tests assert these exact strings (the ones that change fail on the current code). Each expected string evaluates in Python back to the input, so a quick check in
python3is an easy way to confirm a new case. -
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 #233 in the description.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1
- Forks
- 9
- Merge medio
- 9 h 50 min
- PR fusionados (30 d)
- 105
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de codercops/toolbelt
-
JSONPath: big numbers in the results are roundedPosiblemente ocupada @arxh80 la tomó hoy. Abiertobug hacktoberfest help wanted
Dificultad 3/5 1-2 días Aptitud para principiantes 78/100
codercops/toolbelt#238 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Color converter: the contrast ratio shows `4.50 : 1` while Normal AA says FAILPosiblemente ocupada @bercedev la tomó hoy. Abiertobug good first issue hacktoberfest
codercops/toolbelt#235 · 5 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
JSON to YAML: control characters are written raw, so PyYAML and js-yaml can't read the outputPosiblemente ocupada @anurag2787 la tomó hoy. Abiertobug good first issue hacktoberfest
codercops/toolbelt#234 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Add the URL encoder to the README, the home share card and package.jsonPosiblemente ocupada @Abhishek764 la tomó hace 3 días. Abiertodocumentation good first issue hacktoberfest
codercops/toolbelt#153 · 4 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Add a Number Base Converter toolAbiertoenhancement good first issue hacktoberfest new tool
codercops/toolbelt#128 · 9 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de codercops/toolbelt
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
phivk/rubiks-lab#33 ·
Los mantenedores suelen responder en 1 día
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedPosiblemente ocupada @ManyaJain111 la tomó hoy. Abiertobug enhancement possible-duplicate
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
AOSSIE-Org/PictoPy#1637 · 4 comentarios ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
chaitin/MonkeyCode#1437 ·
Los mantenedores suelen responder en 1 día
-
rtdb-info-connected-order test: unhandled 'connection is closed' rejection fails the CLI suiteAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
area:cards enhancement migration ready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
fil-donadoni/tolaria#6309 ·
Los mantenedores suelen responder en 1 día