fix(desktop): validate group padding before hidden ID masking (#12708)

* fix(desktop): validate group padding before hidden ID masking

* test(desktop): compact group padding overrides
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 02:44:32 +00:00
1 parent e53c1a17fc
commit 6cab415894
2 files changed
+14 -7

No files matched your search

@@ -253,6 +253,8 @@ describe.skipIf(process.platform === "win32")(
it.each([
{ before: "", extra: "this is not a key\n", invalidLine: 3 },
{ before: "[Other]\nName=Other\n", extra: "", invalidLine: 1 },
{ header: "\u00a0[Desktop Entry]", invalidLine: 1 },
{ header: "[Desktop Entry]\u00a0", invalidLine: 1 },
{
before: "",
extra: "",
@@ -267,8 +269,8 @@ describe.skipIf(process.platform === "win32")(
},
])(
"refuses a hidden override with malformed structure at line $invalidLine",
async ({ before, extra, trailing = "", invalidLine }) => {
const entry = `${before}[Desktop Entry]\nType=Application\n${extra}Name=User notes\nExec=notes-app\n`;
async ({ before, extra, header, trailing = "", invalidLine }) => {
const entry = `${before ?? ""}${header ?? "[Desktop Entry]"}\nType=Application\n${extra ?? ""}Name=User notes\nExec=notes-app\n`;
const { inspect, file } = await userOverride(
`${entry}Hidden=true\n${trailing}`,
);
@@ -294,10 +296,10 @@ describe.skipIf(process.platform === "win32")(
},
);
it("masks a minimal Application with a localized key and a valid action group", async () => {
it("masks a minimal Application with ASCII group padding and localized keys", async () => {
const { inspect } = await userOverride(
[
"[Desktop Entry]",
"\t[Desktop Entry] \t",
"Type=Application",
'Name=Notes "[Bad[Group]"',
"Name[fr]=Notes locales",
+8 -3
View File
@@ -32,7 +32,10 @@ export interface DesktopEntry {
readonly malformed_line?: number;
}
const GROUP = new RegExp(`^${DESKTOP_GROUP}$`, "u");
// Capture tolerant padding separately so it stays available for validation.
const GROUP = new RegExp(String.raw`^(\s*)${DESKTOP_GROUP}(\s*)$`, "u");
const GLIB_GROUP_LEADING_SPACE = /^[ \t\f\r]*$/u;
const GLIB_GROUP_TRAILING_SPACE = /^[ \t]*$/u;
const INVALID_GROUP_NAME_CHARACTER = /[[\]\u0000-\u001f\u007f]/u;
const LINE_WITH_SEPARATOR = new RegExp(`(${DESKTOP_LINE_BREAK})`, "u");
// Only LF separates records; Unicode line/paragraph separators are value data.
@@ -123,11 +126,13 @@ const readDesktopEntryFields = (text: string) => {
const raw = parts[index]!;
const line = raw.trim();
if (line.length === 0 || line.startsWith("#")) continue;
const header = GROUP.exec(line)?.[1];
const [, leading = "", header, trailing = ""] = GROUP.exec(raw) ?? [];
if (header !== undefined) {
if (
(group === undefined && header !== DESKTOP_ENTRY_GROUP) ||
INVALID_GROUP_NAME_CHARACTER.test(header)
INVALID_GROUP_NAME_CHARACTER.test(header) ||
!GLIB_GROUP_LEADING_SPACE.test(leading) ||
!GLIB_GROUP_TRAILING_SPACE.test(trailing)
)
malformedLine ??= index / 2 + 1;
// Preserve the group boundary for tolerant field and rewrite consumers.