From c09f7172cfcdcae9d0f887ea15f2a87e23919e3e Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:26:52 -0500 Subject: [PATCH] fix(desktop): honor disabled APT source stanzas (#12501) * fix(desktop): honor disabled APT source stanzas * fix(desktop): match APT flags and cover numeric zero forms * fix(desktop): preserve deb822 field whitespace semantics --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> --- src/domain/desktop/aptRepositories.test.ts | 38 ++++++++++++++++++++++ src/domain/desktop/aptRepositories.ts | 32 ++++++++++++++---- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/domain/desktop/aptRepositories.test.ts b/src/domain/desktop/aptRepositories.test.ts index d958fc73f9..f18c61a51b 100644 --- a/src/domain/desktop/aptRepositories.test.ts +++ b/src/domain/desktop/aptRepositories.test.ts @@ -731,3 +731,41 @@ describe("repository kinds and key files", () => { expect(dearmorPublicKeys(Buffer.from("not a key"))).toBeUndefined(); }); }); + +it("keeps APT's source positions when a false Enabled field disables a stanza", () => { + const source = (enabled: string) => + `Types: deb\nURIs: https://example.org/repo\nSuites: stable\nComponents: main\nEnabled: ${enabled}\n`; + const disabled = [ + "false", + "0", + "Off", + "without", + "disable", + "+0", + "-0", + "0x0", + "-0x0", + "\tFaLsE \t", + "\n false", + "\n\t-0", + ]; + const enabled = [ + "yes", + "1", + "0x1", + "-1", + "0.0", + "fal\u017fe", + "\u00a0false", + "false\u00a0", + "\u3000FaLsE\u3000", + "\n\tfalse", + ]; + const stanzas = parseDeb822Sources( + Buffer.from([...disabled, ...enabled].map(source).join("\n")), + "example.sources", + ); + expect(stanzas.map((entry) => entry.position)).toEqual( + enabled.map((_, index) => disabled.length + index + 1), + ); +}); diff --git a/src/domain/desktop/aptRepositories.ts b/src/domain/desktop/aptRepositories.ts index 7a4491c057..5ed451972c 100644 --- a/src/domain/desktop/aptRepositories.ts +++ b/src/domain/desktop/aptRepositories.ts @@ -190,6 +190,10 @@ export const parseOneLineSources = ( ]; }); +// Match the ASCII whitespace recognized by APT's tag reader within a line. +const trimDeb822Line = (value: string): string => + value.replace(/^[ \t\v\f\r]+|[ \t\v\f\r]+$/gu, ""); + /** Fields of each deb822 paragraph by lowercase name; continuation lines keep their line breaks. */ export const deb822Paragraphs = ( text: string | Buffer, @@ -209,22 +213,36 @@ export const deb822Paragraphs = ( for (const line of sourceLines(text)) { if (line === undefined) { readable = false; - } else if (line.trim().length === 0) { + continue; + } + const content = trimDeb822Line(line); + if (content.length === 0) { finish(); } else if (line.startsWith("#")) continue; - else if (/^[ \t]/u.test(line) && last !== undefined) - current.set(last, `${current.get(last) ?? ""}\n${line.trim()}`); - else { + else if (/^[ \t]/u.test(line) && last !== undefined) { + const previous = current.get(last) ?? ""; + // APT skips an initial newline only before a space-led continuation. + current.set( + last, + previous === "" && line.startsWith(" ") + ? content + : `${previous}\n${content}`, + ); + } else { const colon = line.indexOf(":"); if (colon <= 0) continue; - last = line.slice(0, colon).trim().toLowerCase(); - current.set(last, line.slice(colon + 1).trim()); + last = trimDeb822Line(line.slice(0, colon)).toLowerCase(); + current.set(last, trimDeb822Line(line.slice(colon + 1))); } } finish(); return found; }; +// APT's numeric conversion skips leading ASCII whitespace, including a +// retained newline before a tab-led continuation. Its word comparison is exact. +const APT_DISABLED = /^(?:no|false|without|off|disable|\n*[+-]?(?:0+|0x0+))$/u; + /** The `deb` stanzas of a deb822 `.sources` file; disabled paragraphs are skipped but still counted. */ export const parseDeb822Sources = ( text: string | Buffer, @@ -233,7 +251,7 @@ export const parseDeb822Sources = ( deb822Paragraphs(text).flatMap((fields, index) => { if ( !fieldValues(fields.get("types")).includes("deb") || - fields.get("enabled")?.toLowerCase() === "no" + APT_DISABLED.test(fields.get("enabled")?.toLowerCase() ?? "") ) return []; return [