From 87754d2df209f254531b1a7020d72650aae66a6d Mon Sep 17 00:00:00 2001 From: le king fu Date: Fri, 23 Oct 2026 20:30:01 -0400 Subject: [PATCH] fix(db): keep no folder holding ;, |, a backtick or ) in Journal lines (#478) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit withoutFolders ended a path at a backtick, `;`, `|` or a `)` not followed by a separator, so a folder name that holds one of them stayed in the Journal line, or its start did: `C:\Users\Jean (Work) Smith\AppData\x.db` gave `Jean (Work) x.db`, `C:\Users\jean\My;Docs\x.db` gave `My;Docs-x.db`. An error line of the Journal can go with a feedback report. PATH_STOP is reduced to a line break and a double quote, and the `)` branch of lastSeparator is gone (option B, Max's decision of 2026-10-20). A path now runs to its last separator before a line break, a double quote, a `,` or `:` followed by a blank, or a blank followed by another path. The conservative rule pays for it: `/a/x.db; I/O` gives `O` and `(see /a/x.db) and I/O` gives `(see O`, pinned by the test « drops more text rather than a folder ». Co-Authored-By: Claude Opus 5.5 --- src/services/db.test.ts | 52 ++++++++++++++++++++++++++++++++++++----- src/services/db.ts | 34 ++++++++++++++++----------- 2 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/services/db.test.ts b/src/services/db.test.ts index 1ec3e4e..4a66a17 100644 --- a/src/services/db.test.ts +++ b/src/services/db.test.ts @@ -700,6 +700,21 @@ describe("describePreparation (#390)", () => { } }); + it("writes no folder that holds a `)` followed by a word or a `;` in an error line (#478)", () => { + const lines = describePreparation( + "x.db", + report({ + // A path scrub did not replace, under a user folder `Jean (Work) Smith`. + catch_up_error: + "backup_failed: unable to open database: C:\\Users\\Jean (Work) Smith\\AppData\\Roaming\\com.simpl.resultat\\migration-backups\\x-before-v17.db.tmp", + catch_up_backup: "C:\\Users\\jean\\My;Docs\\x-before-v17.db", + }) + ); + expect(lines.errors).toEqual([ + "Profile x.db: database update stopped: backup_failed: unable to open database: x-before-v17.db.tmp; copy of the previous state kept as x-before-v17.db", + ]); + }); + it("withoutFolders keeps text without a path as is", () => { expect(withoutFolders("migration_failed:v12: near \"x\": syntax error")).toBe( 'migration_failed:v12: near "x": syntax error' @@ -718,7 +733,8 @@ describe("describePreparation (#390)", () => { ["\\\\server\\share\\Jean Dupont\\x.db", "x.db"], ["C:\\Program Files (x86)\\Simpl\\x.db", "x.db"], ['"C:\\Users\\Jean Dupont\\x.db" failed', '"x.db" failed'], - ["(see /home/marie claire/x.db) and I/O", "(see x.db) and I-O"], + // A `)` no longer ends a path: the cut goes to the `/` of `I/O` (#478). + ["(see /home/marie claire/x.db) and I/O", "(see O"], ["path=/home/marie claire/x.db;next", "path=x.db;next"], ])("withoutFolders reduces %s to its last segment", (input, expected) => { const cleaned = withoutFolders(input); @@ -726,6 +742,21 @@ describe("describePreparation (#390)", () => { expect(cleaned).not.toMatch(/Jean|Dupont|marie|claire|Users|home|Program|server/); }); + // A folder name may hold `;`, `|`, a backtick, or a `)` followed by a word: + // none of them ends a path, so no word of that folder stays (#478). + it.each([ + ["C:\\Users\\Jean (Work) Smith\\AppData\\x.db", "x.db"], + ["C:\\Users\\jean\\My;Docs\\x.db", "x.db"], + ["C:\\Users\\jean\\My|Docs\\x.db", "x.db"], + ["C:\\Users\\jean\\My`Docs\\x.db", "x.db"], + ["unable to open C:\\Users\\Jean (Work) Smith\\AppData\\x.db: disk I/O error", "unable to open x.db: disk I-O error"], + ["/home/jean (work)/x.db", "x.db"], + ])("withoutFolders keeps no word of a folder that holds a former stop: %s (#478)", (input, expected) => { + const cleaned = withoutFolders(input); + expect(cleaned).toBe(expected); + expect(cleaned).not.toMatch(/Users|Jean|jean|Work|work|Smith|AppData|My|Docs|home/); + }); + it("withoutFolders ends a path at sentence punctuation and at the next path", () => { expect(withoutFolders("unable to open /home/marie claire/x.db: disk I/O error")).toBe( "unable to open x.db: disk I-O error" @@ -734,9 +765,13 @@ describe("describePreparation (#390)", () => { "read a.db, then b.db" ); expect(withoutFolders("'C:\\a\\b.db' and 'C:\\Users\\Jean Dupont\\d.db'")).toBe("'b.db' and 'd.db'"); + // Past a `)`, the next path still ends the previous one (#478). + expect(withoutFolders("(see /home/marie claire/a.db) and C:\\Users\\Jean Dupont\\b.db")).toBe( + "(see a.db) and b.db" + ); }); - it.each([["\""], [";"], ["|"], ["`"], ["\n"], ["\r"]])("withoutFolders ends the folders at %j", (stop) => { + it.each([["\""], ["\n"], ["\r"]])("withoutFolders ends the folders at %j", (stop) => { expect(withoutFolders(`/home/marie claire/x.db${stop} I/O`)).toBe(`x.db${stop} I-O`); }); @@ -745,8 +780,13 @@ describe("describePreparation (#390)", () => { expect(withoutFolders("cannot open '/home/marie claire/x.db' now")).toBe("cannot open 'x.db' now"); }); - it("withoutFolders drops more text rather than a folder when nothing ends the path", () => { - // Conservative: everything up to the last separator of the line goes. - expect(withoutFolders("/home/marie claire/x.db then I/O")).toBe("O"); - }); + // Conservative: everything up to the last separator of the line goes. `;`, + // `|`, a backtick and `)` may sit in a folder name, so they end nothing + // either, and a suffix after them that holds a separator goes too (#478). + it.each([[" then"], [";"], ["|"], ["`"], [")"]])( + "withoutFolders drops more text rather than a folder when nothing ends the path, after %j", + (after) => { + expect(withoutFolders(`/home/marie claire/x.db${after} I/O`)).toBe("O"); + } + ); }); diff --git a/src/services/db.ts b/src/services/db.ts index 816a272..3ea9346 100644 --- a/src/services/db.ts +++ b/src/services/db.ts @@ -328,8 +328,12 @@ export interface ProfilePreparation { */ const PATH_START = /[\\/]|[A-Za-z]:[\\/]|~[\\/]|\.{1,2}[\\/]|[\\/]/y; const BEFORE_START = /[\s'"`(=:,[]/; -/** What ends the folders of a path for sure: a line break, a double quote or a backtick, `;`, `|`. */ -const PATH_STOP = /[\n\r"`;|]/; +/** + * What ends the folders of a path for sure: a line break or a double quote, + * which Windows forbids in a name and no real folder holds elsewhere. A + * backtick, `;` and `|` can sit in a folder name, so they end nothing (#478). + */ +const PATH_STOP = /[\n\r"]/; /** The last segment of a path: the file name, kept. */ const LAST_SEGMENT = /[^\s"`()<>\\/]*/y; /** @@ -367,8 +371,8 @@ function lastSeparator(text: string, from: number): number { if (PATH_STOP.test(c)) break; // Sentence punctuation: Windows forbids `:` in a name, and no user name holds `,`. if ((c === "," || c === ":") && (next === "" || /\s/.test(next))) break; - // `Program Files (x86)\…` goes on; `(see /x/y.db) and…` stops. - if (c === ")" && next !== "\\" && next !== "/") break; + // No `)` stop: `Jean (Work) Smith\…` is a folder name as much as + // `Program Files (x86)\…` (#478). if (/\s/.test(c) && newPathAfter(text, k)) break; } return last; @@ -378,16 +382,18 @@ function lastSeparator(text: string, from: number): number { * Keep only the last segment of every path in `text`: error lines can be * attached to a feedback report, and a folder holds the OS user name * (Loi 25). A folder may contain blanks (`C:\Users\Jean Dupont\…`, - * `/home/marie claire/…`): from its start, a path runs to its LAST separator - * before a line break, a double quote, a backtick, `;`, `|`, a `,` or `:` - * followed by a blank, a closing parenthesis not followed by a separator, or a - * blank followed by another path. When nothing ends it, the rule is - * conservative: text after a path is dropped up to the last separator of the - * line (`/a/x.db then I/O` gives `O`), rather than letting a folder through. - * Limits in ADR 0021, section 7. A quote right before the path is - * not part of it, so both quotes stay around the file name - * (`'C:\Users\Bob\x.db'` gives `'x.db'`). Any other separator becomes `-` (SQLite's "disk I/O error" reads - * "disk I-O error"), so an error line never contains a `/` nor a `\` (#395). + * `/home/marie claire/…`), a backtick, `;`, `|` or a `)` followed by a word + * (`C:\Users\Jean (Work) Smith\…`, #478): from its start, a path runs to its + * LAST separator before a line break, a double quote, a `,` or `:` followed + * by a blank, or a blank followed by another path. When nothing ends it, the + * rule is conservative: text after a path is dropped up to the last separator + * of the line, rather than letting a folder through. With so few stops, that + * costs a readable suffix: `/a/x.db then I/O` and `/a/x.db; I/O` give `O`, + * `(see /a/x.db) and I/O` gives `(see O`. Limits in ADR 0021, section 7. A + * quote right before the path is not part of it, so both quotes stay around + * the file name (`'C:\Users\Bob\x.db'` gives `'x.db'`). Any other separator + * becomes `-` (SQLite's "disk I/O error" reads "disk I-O error"), so an error + * line never contains a `/` nor a `\` (#395). */ export function withoutFolders(text: string): string { let out = "";