mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
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>
This commit is contained in:
1 parent
83192e9750
commit
c09f7172cf
2 files changed
+63
-7
No files matched your search
@@ -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),
|
||||
);
|
||||
});
|
||||
@@ -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 [
|
||||
|
||||
Reference in new issue
Block a user