mirror of
https://github.com/stablyai/orca.git
synced 2026-09-28 00:02:41 +00:00
fix: ignore malformed markdown file links (#3695)
This commit is contained in:
@@ -123,6 +123,10 @@ describe('resolveMarkdownLinkTarget', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('returns null for malformed percent-encoded file URL paths', () => {
|
||||
expect(resolveMarkdownLinkTarget('file:///repo/docs/%zz.md', SOURCE, ROOT)).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null for empty href', () => {
|
||||
expect(resolveMarkdownLinkTarget('', SOURCE, ROOT)).toBeNull()
|
||||
expect(resolveMarkdownLinkTarget(undefined, SOURCE, ROOT)).toBeNull()
|
||||
|
||||
@@ -51,8 +51,13 @@ function toFileUrl(filePath: string): string {
|
||||
return `file:///${segments.join('/')}`
|
||||
}
|
||||
|
||||
function fileUrlToAbsolutePath(url: URL): string {
|
||||
let absolutePath = decodeURIComponent(url.pathname)
|
||||
function fileUrlToAbsolutePath(url: URL): string | null {
|
||||
let absolutePath: string
|
||||
try {
|
||||
absolutePath = decodeURIComponent(url.pathname)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
// Windows: "/C:/foo" → "C:/foo"
|
||||
if (/^\/[A-Za-z]:\//.test(absolutePath)) {
|
||||
absolutePath = absolutePath.slice(1)
|
||||
@@ -175,6 +180,9 @@ export function resolveMarkdownLinkTarget(
|
||||
}
|
||||
|
||||
const rawAbsolutePath = fileUrlToAbsolutePath(resolved)
|
||||
if (rawAbsolutePath === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Why: hash-based line anchor takes precedence; fall back to trailing
|
||||
// `:line:col` syntax only if no hash anchor was found.
|
||||
|
||||
Reference in New Issue
Block a user