[PR #5945] fix(jsonc): prevent blank lines from commented JSON fields #5426

Open
opened 2026-03-17 02:52:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5945
Author: @sahilkhan09k
Created: 3/5/2026
Status: 🔄 Open

Base: mainHead: fix-jsonc-comment-blank-lines


📝 Commits (2)

  • 0dd298b fix(jsonc): prevent blank lines from commented JSON fields
  • 1b8b3cd fix(jsonc): remove unused stripComments_ import

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/editor/linting/jsonc.ts (+2 -2)

📄 Description

Closes #5629

This PR fixes an issue where commented lines in JSON request bodies generate extra blank lines in the final request sent over the wire, particularly visible in the desktop app.

The issue was caused by the stripComments helper performing a redundant preprocessing step using jsonc-parser.stripComments. This function replaces comment text with whitespace to preserve character offsets, which can leave whitespace-only lines in the processed body when fallback paths are triggered.

Since stripCommentsAndCommas already parses JSONC using jsonc-parser.parseTree (which natively ignores comments), the additional preprocessing step is unnecessary and can lead to malformed whitespace.

What's changed

  • Removed the redundant stripComments_ preprocessing step in stripComments.
  • Passed the original JSONC string directly to stripCommentsAndCommas.
  • Prevented whitespace-only lines from appearing in the final request body when comments are removed.

Notes to reviewers

stripCommentsAndCommas already uses jsonc-parser.parseTree, which supports JSONC syntax including comments. Removing the stripComments_ pre-pass simplifies the pipeline and avoids introducing whitespace padding from comment stripping.

Tested with:

  • multiple commented lines
  • inline comments
  • trailing comma scenarios

This ensures the final request body remains correctly formatted without extra blank lines.


Summary by cubic

Prevent extra blank lines in JSON request bodies when JSONC comments are used. stripComments now passes the original JSONC string to stripCommentsAndCommas, removing the redundant pre-pass that inserted whitespace-only lines and cleaning up the unused stripComments_ import.

Written for commit 1b8b3cd1e6. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5945 **Author:** [@sahilkhan09k](https://github.com/sahilkhan09k) **Created:** 3/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-jsonc-comment-blank-lines` --- ### 📝 Commits (2) - [`0dd298b`](https://github.com/hoppscotch/hoppscotch/commit/0dd298b4e708f3b626ee31ed8dcb67addfe66f56) fix(jsonc): prevent blank lines from commented JSON fields - [`1b8b3cd`](https://github.com/hoppscotch/hoppscotch/commit/1b8b3cd1e65d44f7e210e03c4ace519a84e5b2c6) fix(jsonc): remove unused stripComments_ import ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/editor/linting/jsonc.ts` (+2 -2) </details> ### 📄 Description Closes #5629 This PR fixes an issue where commented lines in JSON request bodies generate extra blank lines in the final request sent over the wire, particularly visible in the desktop app. The issue was caused by the `stripComments` helper performing a redundant preprocessing step using `jsonc-parser.stripComments`. This function replaces comment text with whitespace to preserve character offsets, which can leave whitespace-only lines in the processed body when fallback paths are triggered. Since `stripCommentsAndCommas` already parses JSONC using `jsonc-parser.parseTree` (which natively ignores comments), the additional preprocessing step is unnecessary and can lead to malformed whitespace. ### What's changed - Removed the redundant `stripComments_` preprocessing step in `stripComments`. - Passed the original JSONC string directly to `stripCommentsAndCommas`. - Prevented whitespace-only lines from appearing in the final request body when comments are removed. ### Notes to reviewers `stripCommentsAndCommas` already uses `jsonc-parser.parseTree`, which supports JSONC syntax including comments. Removing the `stripComments_` pre-pass simplifies the pipeline and avoids introducing whitespace padding from comment stripping. Tested with: - multiple commented lines - inline comments - trailing comma scenarios This ensures the final request body remains correctly formatted without extra blank lines. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevent extra blank lines in JSON request bodies when JSONC comments are used. stripComments now passes the original JSONC string to stripCommentsAndCommas, removing the redundant pre-pass that inserted whitespace-only lines and cleaning up the unused stripComments_ import. <sup>Written for commit 1b8b3cd1e65d44f7e210e03c4ace519a84e5b2c6. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5426
No description provided.