Skip to content

fix(menu): prevent trailing comma stripper from eating commas inside strings (#13250) - #13305

Open
Cid-oe wants to merge 3 commits into
omacom:quattrofrom
Cid-oe:fix/issue-13250
Open

Cid-oe wants to merge 3 commits into
omacom:quattrofrom
Cid-oe:fix/issue-13250

Conversation

@Cid-oe

@Cid-oe Cid-oe commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Closes #13250

Description

The stripJsonc utility in MenuModel.js cleans trailing commas to permit JSONC format, but its naive regex (/,(\s*[}\]])/g) would also silently strip commas inside string values (like menu labels) if they happened to be followed by ] or }.

This PR replaces the regex replacement for trailing commas with a fast, string-aware single-pass loop, correctly preserving any , found inside quotes.

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: The stripJsonc change fixes #13250. A comma followed by whitespace and ] or } inside a string is now kept, while real trailing commas are still removed. For valid menu JSONC without such a string, the output is unchanged. The PR also carries a second, unrelated commit that is already open as #13044 and has one known issue there.

input label        "x, ]y"
base  stripJsonc   "x ]y"     comma inside the string removed
head  stripJsonc   "x, ]y"    string kept; trailing commas still removed

Verified: Checked in Node and in Qt's QML engine (run with qml -a core), the engine Quickshell uses to load MenuModel.js through Menu.qml:

  • The Menu JSONC: labels containing , ] or , } are silently corrupted by the trailing-comma stripper #13250 reproduction gives "x ]y" on base and "x, ]y" on head, in both engines.
  • The shipped default/omarchy/omarchy-menu.jsonc strips to byte-identical text on base and head and parses to the same 340 items.
  • In Node, 20,000 generated JSONC documents with random whitespace, trailing commas and full-line comments:
    • Every document without a comma-plus-closer inside a string gives byte-identical output on base and head.
    • Base corrupted almost every document that had one.
  • Escaped quotes and escaped backslashes before a closing quote are handled correctly. Full-line comments are still removed before the scan, so quotes inside comment lines do not affect it.

The PR includes the launch-editor change from #13044

Commit d5c0b8f ("fix(launch-editor): pass wait flags to GUI editors in inline mode (#13037)") changes bin/omarchy-launch-editor and test/shell.d/command-operand-boundaries-test.sh. Its diff is identical to open PR #13044. The title and description here cover only the menu fix, and only #13250 is linked for closing.

The same commit keeps the gnome-text-editor issue already described in the review on #13044. GNOME Text Editor registers no --wait option, and GLib then rejects unknown options, so an inline launch of it exits 1 without opening the file (from GNOME Text Editor and GLib source, not a GUI run). This only affects users who set gnome-text-editor in the defaults file by hand, because Omarchy's editor menu does not offer it.

Impact: Merging this PR would land the #13037 change under a menu-fix title, without closing #13037, and would make #13044 redundant. Other open PRs also change bin/omarchy-launch-editor, including #13094, which drops gnome-text-editor from the list.

Suggested change: Drop commit d5c0b8f here and keep the launch-editor change in #13044, where the gnome-text-editor entry can be removed.

Notes

Optional test improvement: test/shell.d/menu-test.sh covers comment lines and real trailing commas, but not a comma inside a string before ] or }. It passes on both base and head, so it would not catch a return of #13250. An assertion based on the issue's reproduction would fail on base and pass on head, for example parseMenuJsonc('{ "b": { "label": "x, ]y" } }')[0].label === "x, ]y".

Related PRs: #13255 (opened by the reporter of #13250) makes the same string-aware comma change. Its output matched this PR's on every generated and random input in Node. #6525 rewrites the same stripJsonc body for inline comments but keeps the old comma regex, so whichever of these lands second needs a manual merge of the two scanners.


Review information

Test scope: Pinned head bcd1ee3 against merge base 28ceaae.

  • Menu parser: isolated Node runs covering the issue reproduction, targeted edge cases, the shipped menu file, 20,000 generated JSONC documents and 50,000 random short texts, with Fix menu JSONC trailing-comma stripping corrupting string values #13255 compared on the generated and random inputs. A qml -a core run repeated the reproduction, the edge cases and the shipped menu.
  • Launch editor: argument construction checked with stub setsid, uwsm-app and editor binaries. Wait-flag handling was traced from source or documentation for VS Code, Zed, gedit, Sublime Text and GNOME Text Editor; the other VS Code derivatives were not checked separately. No real GUI editor, uwsm session or desktop was started.
  • Repository tests: menu-test.sh and command-operand-boundaries-test.sh run in isolation on head and base.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@buger

buger commented Sep 27, 2026

Copy link
Copy Markdown

Heads-up: this and #13255 fix the same issue (#13250) with the same approach — a string-aware single-pass replacement for the trailing-comma regex. We diff-tested this PR's head against #13255's on the edge corpus (labels and actions with , ] / , }, brace expansions, awk-style actions, escaped quotes, backslash-ended strings, CRLF, real trailing commas including arrays, invalid-stays-invalid): behaviorally identical on every input, and both are correct.

So whichever lands first, the other is redundant — no competition intended; we filed #13250 and sent #13255, and we're equally happy to see this one merge instead. One coordination note: both PRs compose with #6525 (inline comments) only if comment stripping runs before the comma scan — whoever rebases last should keep that order.

Nice work — the equivalence held on every input we threw at it.

Cross-check run with Proof.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

The stripJsonc change looks right. The branch also carries the unrelated omarchy-launch-editor --wait commit from #13044, though. Could you drop that so each PR reviews and lands on its own?

Also, #13968 fixes the same commas-in-strings bug and also handles array roots and inline comments, and #13681 overlaps too. It's worth checking with the maintainers which one they want, so three parsers don't land.

…strings (omacom#13250)

The `stripJsonc` utility in `MenuModel.js` attempts to allow trailing commas
by removing any comma followed immediately by `}` or `]` (with optional
whitespace). Because its regex was not string-aware, it also matched the
sequence `, ]` inside string values, such as menu labels, corrupting them.

This rewrites the trailing-comma removal step as a simple string-aware
character loop. Line comments are still stripped by regex beforehand.

Closes omacom#13250
@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The menu parser now preserves commas inside quoted labels and commands while still removing trailing commas outside strings.

  • Menu values keep their commas when JSONC is cleaned.

Reviews (2) · Last reviewed commit: "Exercise a single escaped quote in the c..." · Reviewed by Greptile

Comment thread shell/plugins/menu/MenuModel.js Resolved
@omarchybot omarchybot added bug Something isn't working and removed enhancement New feature or request labels Nov 18, 2026
omarchybot and others added 2 commits November 18, 2026 07:55
Carry the four omacom#13250 regression assertions from omacom#13968: preserve commas in labels and actions while checking escaped quotes, escaped backslashes and actual trailing commas. They catch a return to the string-blind regex without pulling the separate comment-parser changes into this fix.

Co-Authored-By: Leonid Bugaev <leonsbox@gmail.com>
Co-Authored-By: GPT-6 High <noreply@openai.com>
Co-Authored-By: Opus 5.5 High <noreply@anthropic.com>
Co-Authored-By: muse-wonder via pi, thinking high <noreply@users.noreply.github.com>
Paired escaped quotes toggle string state twice, so a scanner that ignores backslashes can still preserve the following comma. A single escaped quote makes that mistake strip the comma and fail the assertion.

Co-Authored-By: GPT-6 High <noreply@openai.com>
Co-Authored-By: Opus 5.5 High <noreply@anthropic.com>
Co-Authored-By: muse-wonder via pi, thinking high <noreply@users.noreply.github.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Nov 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Added four regression assertions from @buger's #13968 in 7054d4134 for commas in labels and actions, escaped quotes, and escaped backslashes. On a disposable Omarchy ISO worker, my reproduction failed on quattro 419a5a709, passed with this fix, and failed again with the scanner reverted. The added menu test also failed against the base parser and passed with the fix.

The cropped captures show the real menu opened through omarchy menu summon: the base loses the three labels' commas; this head preserves them.

Before: commas are missing from all three menu labels
After: commas remain in the same three menu labels

The full ./test/all run completed without failures on that worker: the CLI suite and 422 shell test files completed, with six files containing skipped checks. The menu test passed all 114 assertions, and the guard test passed all 27. The single-escaped-quote assertion also failed when escape handling was disabled, then passed when it was restored.

Checked by GPT-6 High in Codex, with reviews by Opus 5.5 High and muse-wonder via pi, thinking high. Both reviewers found the final head clean; review independence is not guaranteed.

#13968 and #16195 also fix this comma bug while changing other behavior. #6525 and #13803 overlap the scanner but retain the string-blind comma regex; any conflict resolution involving them needs to preserve these regression cases. The other parser changes were kept out of this PR. Waiting for maintainer review.

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

Labels

bug Something isn't working ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu JSONC: labels containing , ] or , } are silently corrupted by the trailing-comma stripper

5 participants