Skip to content

Commit dbd461c

Browse files
committed
Narrow path-token continuation check in quoted prose
1 parent b50262c commit dbd461c

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/tui/image-attachments.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function scanImagePathLine(
134134
// `notes/plan.png` mints a root-level `/plan.png` mention.
135135
if (
136136
canStartUnquotedPath(text, i, end) &&
137-
(!inQuotedProse || i === start || !isTokenContinuation(text[i - 1]))
137+
(!inQuotedProse || i === start || !isPathTokenContinuation(text[i - 1]))
138138
) {
139139
const match = UNQUOTED_AT.exec(text.slice(i, end));
140140
if (match?.[0] !== undefined) {
@@ -157,14 +157,26 @@ function isWordChar(ch: string | undefined): boolean {
157157
);
158158
}
159159

160-
// Characters that can glue a `/` (or another path start) onto the token
161-
// before it: relative segments (`notes/plan.png`), URLs (`https://x.png`),
162-
// and shell-style quote concatenation (`'a'/b.png`).
163-
const TOKEN_CONTINUATION = "'\"`/\\:.~_-+@%";
164-
165-
function isTokenContinuation(ch: string | undefined): boolean {
160+
// True when `ch` continues the current token (word, `/\:.~`, or quote-glue)
161+
// so a mid-token `/` inside prose must not open a root path.
162+
function isPathTokenContinuation(ch: string | undefined): boolean {
166163
if (ch === undefined) return false;
167-
return isWordChar(ch) || TOKEN_CONTINUATION.includes(ch);
164+
if (isWordChar(ch)) return true;
165+
switch (ch) {
166+
case "/":
167+
case "\\":
168+
case ".":
169+
case "~":
170+
case ":":
171+
case "_":
172+
case "-":
173+
case "'":
174+
case '"':
175+
case "`":
176+
return true;
177+
default:
178+
return false;
179+
}
168180
}
169181

170182
function looksLikeQuotedImagePath(inner: string): boolean {

0 commit comments

Comments
 (0)