mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
fix(desktop): skip only ASCII whitespace before a desktop entry key (#13126)
The key reader stripped each line with JavaScript's trimStart(), which also removes Unicode spaces such as U+00A0 and U+3000. GLib skips only g_ascii_isspace, so it keeps those bytes inside the key and the record never matches Name= or Hidden=. The drift had a safety direction: a line indented with U+00A0 and reading Hidden=true was accepted as a hidden override by REA but never by the desktop environment, so findHiddenDesktopEntry() claimed a deletion that GLib would not honour. #12708 closed this for group headers by validating the captured padding against GLib's ASCII set; the blank-line, comment and key checks still used the Unicode-aware trim. I now strip only [ \t\f\r] before deciding whether a line is blank, a comment or a key, and hand that same string to the record matcher. ASCII indentation still parses as before. The inventory test covers the refusal when a hidden override carries the padding, and the domain tests cover the three Unicode spaces for keys, blank lines and comments.
This commit is contained in:
1 parent
8691cfa96b
commit
a44e705ad8
3 files changed
+45
-2
No files matched your search
@@ -255,6 +255,8 @@ describe.skipIf(process.platform === "win32")(
|
||||
{ before: "[Other]\nName=Other\n", extra: "", invalidLine: 1 },
|
||||
{ header: "\u00a0[Desktop Entry]", invalidLine: 1 },
|
||||
{ header: "[Desktop Entry]\u00a0", invalidLine: 1 },
|
||||
{ before: "", extra: "\u00a0Name=Injected\n", invalidLine: 3 },
|
||||
{ before: "", extra: "\u00a0\n", invalidLine: 3 },
|
||||
{
|
||||
before: "",
|
||||
extra: "",
|
||||
|
||||
@@ -113,6 +113,43 @@ Terminal=true
|
||||
});
|
||||
},
|
||||
);
|
||||
it.each(["\u00a0", "\u3000", "\ufeff"])(
|
||||
"refuses a key indented with %j, which GLib keeps inside the key",
|
||||
(padding) => {
|
||||
const parsed = parseDesktopEntry(
|
||||
`[Desktop Entry]\nType=Application\n${padding}Name=Injected\n`,
|
||||
);
|
||||
expect(parsed).toMatchObject({
|
||||
ok: true,
|
||||
value: { name: null, malformed_line: 3 },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["\u00a0", "\u3000", "\ufeff"])(
|
||||
"does not read a %j line as a blank or a comment",
|
||||
(padding) => {
|
||||
const blank = parseDesktopEntry(
|
||||
`[Desktop Entry]\nType=Application\nName=Notes\n${padding}\n`,
|
||||
);
|
||||
expect(blank).toMatchObject({ ok: true, value: { malformed_line: 4 } });
|
||||
const comment = parseDesktopEntry(
|
||||
`[Desktop Entry]\nType=Application\nName=Notes\n${padding}# Hidden=true\n`,
|
||||
);
|
||||
expect(comment).toMatchObject({ ok: true, value: { malformed_line: 4 } });
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps accepting keys indented with ASCII spaces and tabs", () => {
|
||||
const parsed = parseDesktopEntry(
|
||||
"[Desktop Entry]\nType=Application\n \tName=Notes\n Exec=notes\n \t # note\n",
|
||||
);
|
||||
expect(parsed).toMatchObject({
|
||||
ok: true,
|
||||
value: { name: "Notes", exec: "notes" },
|
||||
});
|
||||
expect(parsed.ok && parsed.value).not.toHaveProperty("malformed_line");
|
||||
});
|
||||
});
|
||||
|
||||
describe("tokenizeDesktopExec", () => {
|
||||
|
||||
@@ -36,6 +36,10 @@ export interface DesktopEntry {
|
||||
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;
|
||||
// GLib skips only its ASCII whitespace before a key or a comment. A record that
|
||||
// starts with any other Unicode space keeps that space in the key, so the line
|
||||
// is malformed rather than parsed with the space removed.
|
||||
const GLIB_LINE_LEADING_SPACE = /^[ \t\f\r]*/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.
|
||||
@@ -124,7 +128,7 @@ const readDesktopEntryFields = (text: string) => {
|
||||
let malformedLine: number | undefined;
|
||||
for (let index = 0; index < parts.length; index += 2) {
|
||||
const raw = parts[index]!;
|
||||
const line = raw.trim();
|
||||
const line = raw.replace(GLIB_LINE_LEADING_SPACE, "");
|
||||
if (line.length === 0 || line.startsWith("#")) continue;
|
||||
const [, leading = "", header, trailing = ""] = GROUP.exec(raw) ?? [];
|
||||
if (header !== undefined) {
|
||||
@@ -141,7 +145,7 @@ const readDesktopEntryFields = (text: string) => {
|
||||
continue;
|
||||
}
|
||||
// Full-line trimming is syntax-only: string-value suffixes are data.
|
||||
const entry = ENTRY.exec(raw.trimStart());
|
||||
const entry = ENTRY.exec(line);
|
||||
if (group === undefined || entry?.groups === undefined) {
|
||||
malformedLine ??= index / 2 + 1;
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user