Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#233 3 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@anurag2787 ci sta già lavorando.

Dal 21/10/2026.

  • #243 di @ElectLive — chiusa senza merge

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
TypeScript
Stelle
1
Fork
9
Merge medio
9h 50m
PR unite (30g)
105

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codercops/toolbelt

Tutte le issue di codercops/toolbelt

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.