From 3d4b930b603a15c2c600212b7c325c1585853f5a Mon Sep 17 00:00:00 2001 From: Siddharth U Date: Sat, 26 Sep 2026 15:10:07 +0530 Subject: [PATCH 1/3] fix(menu): prevent trailing comma stripper from eating commas inside strings (#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 #13250 --- shell/plugins/menu/MenuModel.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/shell/plugins/menu/MenuModel.js b/shell/plugins/menu/MenuModel.js index c6c75f254fff..33e0711a0714 100644 --- a/shell/plugins/menu/MenuModel.js +++ b/shell/plugins/menu/MenuModel.js @@ -1,7 +1,26 @@ function stripJsonc(raw) { - return String(raw || "") - .replace(/^\s*\/\/[^\n]*(\n|$)/gm, "") - .replace(/,(\s*[}\]])/g, "$1") + var s = String(raw || "").replace(/^\s*\/\/[^\n]*(\n|$)/gm, ""); + var out = ""; + var inString = false; + var escape = false; + for (var i = 0; i < s.length; i++) { + var c = s[i]; + if (escape) { + escape = false; + } else if (c === '"') { + inString = !inString; + } else if (c === '\\' && inString) { + escape = true; + } + + if (!inString && c === ',') { + var j = i + 1; + while (j < s.length && /\s/.test(s[j])) j++; + if (j < s.length && (s[j] === '}' || s[j] === ']')) continue; + } + out += c; + } + return out; } function normalizeAliases(value) { From 5a4faaef4d44e33e25e68672236663a6da41502f Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 18 Nov 2026 07:55:38 +0100 Subject: [PATCH 2/3] Cover commas inside menu JSONC strings Carry the four #13250 regression assertions from #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 Co-Authored-By: GPT-6 High Co-Authored-By: Opus 5.5 High Co-Authored-By: muse-wonder via pi, thinking high --- test/shell.d/menu-test.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/shell.d/menu-test.sh b/test/shell.d/menu-test.sh index 3a73db494ca8..2d9258df0803 100644 --- a/test/shell.d/menu-test.sh +++ b/test/shell.d/menu-test.sh @@ -40,6 +40,14 @@ const parsed = menu.parseMenuJsonc(` `) assertEqual(parsed.length, 3, 'menu parses JSONC with comments and trailing commas') + +// String-aware trailing commas (#13250) +const withCommasInStrings = menu.parseMenuJsonc('{\n "b": { "label": "x, ]y", "action": "mv f{.bak,}" },\n}') +assertEqual(withCommasInStrings[0].label, 'x, ]y', 'menu keeps a comma before ] inside a label') +assertEqual(withCommasInStrings[0].action, 'mv f{.bak,}', 'menu keeps a comma before } inside an action') +assertEqual(menu.parseMenuJsonc('{"a": {"label": "q\\\\"},}')[0].label, 'q\\', 'menu ends a string at a quote after an escaped backslash before a trailing comma') +assertEqual(menu.parseMenuJsonc('{"a": {"label": "say \\"hello\\", }"}}')[0].label, 'say "hello", }', 'menu keeps a comma before } after an escaped quote inside a label') + assertDeepEqual( parsed.find(item => item.id === 'style.theme'), { From 7054d4134ae75ad22b7ebe239fd19c485c96bd87 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 18 Nov 2026 08:01:13 +0100 Subject: [PATCH 3/3] Exercise a single escaped quote in the comma regression 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 Co-Authored-By: Opus 5.5 High Co-Authored-By: muse-wonder via pi, thinking high --- test/shell.d/menu-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/shell.d/menu-test.sh b/test/shell.d/menu-test.sh index 2d9258df0803..96de8ec10b62 100644 --- a/test/shell.d/menu-test.sh +++ b/test/shell.d/menu-test.sh @@ -46,7 +46,7 @@ const withCommasInStrings = menu.parseMenuJsonc('{\n "b": { "label": "x, ]y", " assertEqual(withCommasInStrings[0].label, 'x, ]y', 'menu keeps a comma before ] inside a label') assertEqual(withCommasInStrings[0].action, 'mv f{.bak,}', 'menu keeps a comma before } inside an action') assertEqual(menu.parseMenuJsonc('{"a": {"label": "q\\\\"},}')[0].label, 'q\\', 'menu ends a string at a quote after an escaped backslash before a trailing comma') -assertEqual(menu.parseMenuJsonc('{"a": {"label": "say \\"hello\\", }"}}')[0].label, 'say "hello", }', 'menu keeps a comma before } after an escaped quote inside a label') +assertEqual(menu.parseMenuJsonc('{"a": {"label": "say \\"hi, }"}}')[0].label, 'say "hi, }', 'menu keeps a comma before } after an escaped quote inside a label') assertDeepEqual( parsed.find(item => item.id === 'style.theme'),