From 50a12e2140c0e9803124e5c21883afd6cc8283c9 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Fri, 24 Apr 2026 11:34:37 +0700 Subject: [PATCH] Reduce assistant file link parser complexity --- packages/app/src/utils/inline-path.ts | 40 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/app/src/utils/inline-path.ts b/packages/app/src/utils/inline-path.ts index 6dfa47fb5..fcdd506db 100644 --- a/packages/app/src/utils/inline-path.ts +++ b/packages/app/src/utils/inline-path.ts @@ -148,6 +148,30 @@ export function parseFileProtocolUrl(value: string): InlinePathTarget | null { }; } +function parseAssistantInlinePathLink( + value: string, + options: AssistantHrefParseOptions, +): InlinePathTarget | null { + const inlinePathTarget = parseInlinePathToken(value); + if (!inlinePathTarget) { + return null; + } + + const normalizedPath = normalizePathToken(inlinePathTarget.path); + if (!normalizedPath || !isAbsolutePath(normalizedPath)) { + return null; + } + + if (!isAllowedAbsolutePath(normalizedPath, options.workspaceRoot)) { + return null; + } + + return { + ...inlinePathTarget, + path: normalizedPath, + }; +} + export function parseAssistantFileLink( value: string, options: AssistantHrefParseOptions = {}, @@ -166,19 +190,11 @@ export function parseAssistantFileLink( return null; } - const inlinePathTarget = parseInlinePathToken(trimmed); + const inlinePathTarget = parseAssistantInlinePathLink(trimmed, { + workspaceRoot: options.workspaceRoot, + }); if (inlinePathTarget) { - const normalizedPath = normalizePathToken(inlinePathTarget.path); - if ( - normalizedPath && - isAbsolutePath(normalizedPath) && - isAllowedAbsolutePath(normalizedPath, options.workspaceRoot) - ) { - return { - ...inlinePathTarget, - path: normalizedPath, - }; - } + return inlinePathTarget; } const windowsPathMatch = trimmed.match(/^([A-Za-z]:[\\/][^?#]*)(#[^?]+)?$/);