Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

JSON formatter: a duplicate key crashes the whole tool

Đã đóng
#218 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@lb1192176991-lab đang làm issue này rồi.

Từ ngày 20/10/2026.

  • #222 của @lb1192176991-lab — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
next.js, typescript

Hướng nghiên cứu

Start with lib/json-utils.ts, comparing the six llParse(raw) call sites with the existing error handling in format() and minify(). Add focused tests for toCSV, toTypeScript, toYAML, toXML, toQueryString, and sortKeys, then verify that the conversion panel remains on the page. Run npm run lint, npm run test, and npm run build; an open linked PR already exists for issue #222.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug good first issue hacktoberfest

Paste this into the JSON formatter:

{"a": 1, "a": 2}

The whole tool is replaced by "This tool hit an unexpected error" (app/error.tsx).

validate() (lib/json-utils.ts, line 71) checks the input with JSON.parse, which accepts a duplicate key and keeps the last value. The conversions then parse the input again with lossless-json, which throws Duplicate key 'a' encountered at position 10. format() and minify() catch that and return it as an error (lines 91 to 95), but these six don't:

  • toCSV (line 137), toTypeScript (line 315), toYAML (line 422), toXML (line 580) and toQueryString (line 623)
  • sortKeys (line 503)

The conversion panel runs one of them while it renders (ConversionPanel.tsx, line 49, and TypeScript is the default mode), so the error reaches the error page. Sort keys throws from its click handler (JsonFormatterClient.tsx, line 109) instead of showing a message.

What to do

  • Catch the parse error in those six functions and return { ok: false, error: parseSyntaxError(raw, e) }, the way format() does. One small helper that all six call is fine.
  • The panel and Sort keys then show "Duplicate key 'a' encountered at position 10", like Format does, and the page stays up.

Where to look

  • lib/json-utils.ts: validate (line 71), format (line 86) and the six llParse(raw) calls above
  • app/(tools)/json-formatter/components/ConversionPanel.tsx: the useMemo at line 49
  • lib/__tests__/json-tree.test.ts renders a component with renderToStaticMarkup, if you also want a test for the panel

Acceptance criteria

  • With {"a": 1, "a": 2} in the editor, the page stays up, and the TypeScript, CSV, YAML, XML and Query string modes show the duplicate key error
  • Sort keys shows the same error
  • Tests: each of the six functions returns ok: false for a duplicate key (they throw on the current code)
  • 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 #218 in the description.

Ngôn ngữ chính
TypeScript
Star
1
Fork
9
Merge trung bình
7 giờ 30 phút
Pull request đã merge (30 ngày)
151

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codercops/toolbelt

Tất cả issue của codercops/toolbelt

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.