Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#233 3 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@anurag2787 已经在做这个了。

开始于 2026年10月21日。

  • #243 来自 @ElectLive —— 已关闭,未合并

评估

这个 Issue 还没有评估数据。

描述

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.

主要语言
TypeScript
星标
1
派生
9
平均合并
9 小时 50 分钟
30 天内合并 PR
105

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codercops/toolbelt 的其他 Issue

查看 codercops/toolbelt 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。