mirror of
https://github.com/stablyai/orca.git
synced 2026-10-20 08:03:28 +00:00
Guard markdown preview anchor decoding
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Worktree } from '../../../../shared/types'
|
||||
import {
|
||||
decodeMarkdownPreviewAnchor,
|
||||
deriveMarkdownPreviewSourceRoot,
|
||||
findMarkdownPreviewOpenedEditFileId,
|
||||
findMarkdownPreviewSourceOpenFile,
|
||||
@@ -31,6 +32,10 @@ function makeWorktree(id: string, path: string): Worktree {
|
||||
}
|
||||
|
||||
describe('MarkdownPreview source link routing', () => {
|
||||
it('falls back to the raw anchor when percent-decoding fails', () => {
|
||||
expect(decodeMarkdownPreviewAnchor('%E0%A4%A')).toBe('%E0%A4%A')
|
||||
})
|
||||
|
||||
it('keeps the explicit source worktree when it exists', () => {
|
||||
const source = makeWorktree('wt-source', '/repo')
|
||||
const nested = makeWorktree('wt-nested', '/repo/packages/app')
|
||||
|
||||
@@ -315,6 +315,14 @@ function parseLineTarget(hash: string): { line: number; column?: number } | null
|
||||
return { line: Number(match[1]), column: match[2] ? Number(match[2]) : undefined }
|
||||
}
|
||||
|
||||
export function decodeMarkdownPreviewAnchor(rawAnchor: string): string {
|
||||
try {
|
||||
return decodeURIComponent(rawAnchor)
|
||||
} catch {
|
||||
return rawAnchor
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeMarkdownPreviewAbsolutePath(absolutePath: string): string {
|
||||
return absolutePath.replaceAll('\\', '/')
|
||||
}
|
||||
@@ -684,7 +692,7 @@ export default function MarkdownPreview({
|
||||
return false
|
||||
}
|
||||
|
||||
const decodedAnchor = decodeURIComponent(rawAnchor)
|
||||
const decodedAnchor = decodeMarkdownPreviewAnchor(rawAnchor)
|
||||
let target: HTMLElement | null = null
|
||||
for (const candidate of body.querySelectorAll<HTMLElement>('[id]')) {
|
||||
if (candidate.id === decodedAnchor) {
|
||||
|
||||
Reference in New Issue
Block a user