fix: a period that ends a sentence also ends the known folder (#497)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 2m24s
PR Check — Rust / rust (pull_request) Successful in 4m40s

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 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-10-26 21:43:08 -04:00
commit eecbd2b626
2 changed files with 12 additions and 5 deletions

View file

@ -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);
});

View file

@ -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 {