Skip to content

Fix JSONC inline comments and reject root arrays in MenuModel (#13492, #13493) - #13803

Open
szaidi-code wants to merge 1 commit into
omacom:quattrofrom
szaidi-code:fix/menu-jsonc-inline-comments-13492
Open

szaidi-code wants to merge 1 commit into
omacom:quattrofrom
szaidi-code:fix/menu-jsonc-inline-comments-13492

Conversation

@szaidi-code

Copy link
Copy Markdown
Contributor

Closes #13492
Closes #13493

Summary

Inline comments (// or /* */) on items in omarchy-menu.jsonc were improperly stripped, corrupting URLs or paths containing //, and root JSON arrays could cause TypeError exceptions.

Changes

  • Update stripJsonc with character scanning to properly strip inline // and /* */ comments without corrupting strings in shell/plugins/menu/MenuModel.js.
  • Guard against root arrays returning [].
  • Add test assertions in test/shell.d/menu-test.sh.

@sanjyay

sanjyay commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Independent community review

This is an independent community review and unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Tested: stripJsonc comment parsing, block comment stripping, root array rejection, and menu test suites in an isolated Omarchy test VM environment.

Findings & Feedback:
The parser correctly handles inline // comments without stripping // inside URLs, supports /* */ block comments, and rejects root arrays (Array.isArray(parsed)). However, there is an edge case in trailing comma removal:

  1. Trailing comma regex modifies string literal contents:
    At line 64 of shell/plugins/menu/MenuModel.js:

    return out.replace(/,(\s*[}\]])/g, "$1")

    Because this regex runs across the entire returned string after the token loop, any string literal containing ,} or , ] (e.g. in labels, commands, or action descriptions) has its comma stripped.
    For example:

    menu.parseMenuJsonc('{"items": {"demo": {"label": "item, }with bracket"}}}')
    // Parses label as: "item }with bracket" (comma is eaten)

    Suggested fix: Handle trailing commas inside the character scanner loop when !inString (e.g. lookahead past whitespace for } or ]), rather than running a global regex over the final output.

  2. Prior open work (Parse menu JSONC with string-aware comments and object roots #13681):
    PR Parse menu JSONC with string-aware comments and object roots #13681 addresses these same two issues (Menu JSONC: a top-level array root is silently read as menu rows with ids "0", "1", … #13492 and Menu JSONC: an inline // comment tail silently empties every entry in that menu file #13493) and handles trailing commas within the character scanner, while also updating docs/menu.md. It may be worth coordinating with that PR to avoid duplicate work.

Testing details
  • Tested PR commit: 429f6190aa6ebbe5045610815152eb40d6c4f039
  • Reproduction in VM:
    const menu = require('shell/plugins/menu/MenuModel.js')
    console.log(menu.parseMenuJsonc('{"items": {"demo": {"label": "foo, }bar"}}}')[0].label)
    // Output: 'foo }bar' (expected 'foo, }bar')
  • Test suites:
    • bash test/shell.d/menu-test.sh: 128/128 passed
    • bash test/shell.d/menu-guards-test.sh: 17/17 passed
    • git diff --check origin/quattro: clean

If you'd prefer not to receive these independent reviews on your PRs, reply to this comment, and I won't review your future PRs.

@omarchybot omarchybot added the bug Something isn't working label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @szaidi-code. I read this against quattro (a85e29a) alongside the other open pull requests that change stripJsonc for the same bugs: #13968, #13681 and #6525. Codex Medium compared the four separately and was asked which fix is best without being told my answer. It also picked #13968, and its independence is not guaranteed. Neither of us ran this on a worker. Since another pull request fixes the same bugs more completely, this one did not get a test run.

The array-root guard is right, and the string-aware scan does fix the inline // tail from #13493 without touching // inside a URL. Two things keep it behind #13968:

#13968 also fixes #13492 and #13493 and keeps the shipped sample extension parsing once its example rows are uncommented. Choosing between these pull requests is the maintainer's call, so this is waiting on them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

4 participants