From eecbd2b626276c7a79ba8000712dfaa41301ee76 Mon Sep 17 00:00:00 2001 From: le king fu Date: Mon, 26 Oct 2026 21:43:08 -0400 Subject: [PATCH] fix: a period that ends a sentence also ends the known folder (#497) The boundary after a known folder counted any "." as part of a name, so "cannot open /home/max." kept the home folder, and withoutFolders would then have kept its last segment, the user name. A "." now continues the name only when a letter, mark, digit, "_" or "-" follows it: /home/max.old and /home/max.2 stay, "/home/max." becomes "~.". Found by the author's self-review. Resolves #497 Co-Authored-By: Claude Opus 5.5 --- src/services/logFolders.test.ts | 5 +++++ src/services/logFolders.ts | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/services/logFolders.test.ts b/src/services/logFolders.test.ts index f3fd0b0..df452f0 100644 --- a/src/services/logFolders.test.ts +++ b/src/services/logFolders.test.ts @@ -80,6 +80,7 @@ describe("replaceKnownFolders (#497)", () => { ["/home/maxime/x.db"], ["/home/max2/x.db"], ["/home/max.old/x.db"], + ["/home/max.2/x.db"], ["/home/max-dev/x.db"], ["/home/max_b/x.db"], ["/home/maxé/x.db"], @@ -97,6 +98,10 @@ describe("replaceKnownFolders (#497)", () => { ["/home/max: no such file", "~: no such file"], ["/home/max then", "~ then"], ["/home/max", "~"], + // A period that ends a sentence, not a name. + ["cannot open /home/max.", "cannot open ~."], + ["cannot open /home/max. Retry", "cannot open ~. Retry"], + ["/home/max..", "~.."], ])("replaces the folder followed by what ends a name: %j", (text, expected) => { expect(replaceKnownFolders(text, LINUX)).toBe(expected); }); diff --git a/src/services/logFolders.ts b/src/services/logFolders.ts index ca16bd6..94efa10 100644 --- a/src/services/logFolders.ts +++ b/src/services/logFolders.ts @@ -39,12 +39,14 @@ interface FolderPattern { } /** - * A character that continues a folder name. The match needs anything else - * right after the folder (a separator, the end of the text, a blank, a quote, - * a parenthesis...), so `/home/max` touches neither `/home/maxime` nor - * `/home/max.old`. + * What continues a folder name right after it: a letter, a mark, a digit, `_` + * or `-`, or a `.` followed by one of them. The match needs anything else (a + * separator, the end of the text, a blank, a quote, a parenthesis, the period + * of a sentence...), so `/home/max` touches neither `/home/maxime` nor + * `/home/max.old`, and `cannot open /home/max.` still loses it. */ -const NAME_GOES_ON = "[\\p{L}\\p{M}\\p{N}_.-]"; +const NAME_CHAR = "[\\p{L}\\p{M}\\p{N}_-]"; +const NAME_GOES_ON = `${NAME_CHAR}|\\.${NAME_CHAR}`; /** Every character with a meaning in a pattern, escaped: a folder name may hold `(`, `)`, `$`, `^`, `{` or `.` (CWE-185). */ function escapeSegment(segment: string): string {