Skip to content

Parse menu JSONC with string-aware comments and object roots - #13681

Closed
AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:cursor/fix-menu-jsonc-parse-ef3e
Closed

AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:cursor/fix-menu-jsonc-parse-ef3e

Conversation

@AnPod

@AnPod AnPod commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Test plan

Note: AnPod #30 rewrites the same stripJsonc for string commas only; this PR is the one that closes #13493/#13492 and includes those regressions.

Strip inline // comment tails outside strings so one trailing note no
longer empties the menu, reject array roots that became phantom "0"/"1"
rows, and keep commas inside string labels while stripping trailing ones.

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @AnPod. I read this against quattro (a85e29a) alongside the other open pull requests that change stripJsonc: #13968, #13305 and #6525. Codex Medium reviewed 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 better, this one did not get a test run.

The array-root guard and the string-aware handling of // and commas inside strings are right. One case regresses, though: a trailing comma, then a // comment line, then }. The comma lookahead at shell/plugins/menu/MenuModel.js:40 skips only [ \t\r\n], so when it reaches / it keeps the comma. The comment is stripped after that, and JSON.parse then gets ,\n} and throws. quattro parses this input to one row, and this branch drops the whole file:

{
  "a": {"label": "A"},
  // note
}

That is the shape of the shipped config/omarchy/extensions/omarchy-menu.jsonc when a user uncomments the three personal example rows and leaves the comments below them, so all of their extension entries would vanish without any message. The same happens to an aliases array that ends in a comma before a comment line. A smaller regression: a no-break space or a mid-file BOM in front of a // comment used to be removed together with the comment by ^\s*//. Here the space is copied through and JSON.parse rejects it.

#13968 fixes the same three issues (#13250, #13492, #13493) the same way. Its comma lookahead also skips // comments, and it reads non-ASCII whitespace outside strings as a space, so it handles both cases above. #13305 fixes only #13250, and #6525 leaves #13250 and #13492 open. All four change the same lines, so whichever lands first makes the others conflict.

This is now waiting on the maintainer to choose between this pull request and #13968. If they would rather take this one, the change it needs is #13968's lookahead, which skips // comments as well as whitespace before deciding a comma is trailing, together with a test for the input above.

buger added a commit to probelabs/omarchy that referenced this pull request Oct 4, 2026
… input-domain SW-REQ-261001-BNZG

- SW-REQ-260927-66FW: next_char_closes_json is now "the next character
  that is neither whitespace nor part of a // comment is } or ]", so the
  requirement no longer encodes the next-non-whitespace rule that
  omacom#13512/omacom#13681 shipped.
- SW-REQ-260928-BMFE (array root) and SW-REQ-260928-C8W1 (comments,
  line break kept) re-applied from e797ba5 onto the PR code.
- SW-REQ-261001-BNZG (new): the stripper's input domain - any JS \s
  character outside strings is whitespace (line feed kept, others become
  one ASCII space), a leading BOM is accepted, strings are verbatim.
  malformed_input with required nominal/negative/differential evidence.
- E4J2/3T3F/PPDW prose and hazard rationale moved from the two regex
  passes to the PR scanner; DEFECT-260927-CMMA/-260928-4NG9/-260928-7AX9
  and REVIEW-21/72/73 re-pointed to the PR; REVIEW-261001-ENZ2 (BNZG).
- Implements annotations on stripJsonc/parseMenuJsonc;
  independence re-verified (59 guarantees). The 129 menu variables fit
  the budget of 130 that the baseline now sets (quattro-proof 4f1a819).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
buger added a commit to probelabs/omarchy that referenced this pull request Oct 5, 2026
… input-domain SW-REQ-261001-BNZG

- SW-REQ-260927-66FW: next_char_closes_json is now "the next character
  that is neither whitespace nor part of a // comment is } or ]", so the
  requirement no longer encodes the next-non-whitespace rule that
  omacom#13512/omacom#13681 shipped.
- SW-REQ-260928-BMFE (array root) and SW-REQ-260928-C8W1 (comments,
  line break kept) re-applied from e797ba5 onto the PR code.
- SW-REQ-261001-BNZG (new): the stripper's input domain - any JS \s
  character outside strings is whitespace (line feed kept, others become
  one ASCII space), a leading BOM is accepted, strings are verbatim.
  malformed_input with required nominal/negative/differential evidence.
- E4J2/3T3F/PPDW prose and hazard rationale moved from the two regex
  passes to the PR scanner; DEFECT-260927-CMMA/-260928-4NG9/-260928-7AX9
  and REVIEW-21/72/73 re-pointed to the PR; REVIEW-261001-ENZ2 (BNZG).
- Implements annotations on stripJsonc/parseMenuJsonc;
  independence re-verified (59 guarantees). The 129 menu variables fit
  the budget of 130 that the baseline now sets (quattro-proof 4f1a819).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

AnPod commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of the competing #13968 / #13305 / #6525.

@AnPod AnPod closed this Oct 23, 2026
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

3 participants