Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

JSON formatter: Escape for code gives broken Python when the text has a run of single quotes

Abierto
#233 3 comentarios 0 reacciones 1 asignado Ver en GitHub

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

bug good first issue hacktoberfest

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: the escapeForCode python tests (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 python3 is an easy way to confirm a new case.
  • npm run lint, npm run test and npm run build pass

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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de codercops/toolbelt

Todos los issues de codercops/toolbelt

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.