Files
orca/src/shared/doc-preview-scheme.test.ts
T
Jinwoo Hong b19a397d3e feat(browser-preview): reland remote HTML document previews (STA-5758) (#16920)
Reapply the reverted remote HTML document preview implementation so remote workspace files render locally over the orca-preview scheme.
2026-08-28 00:27:01 -04:00

46 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { buildDocPreviewUrl, parseDocPreviewUrl } from './doc-preview-scheme'
const GRANT = 'a'.repeat(32)
describe('doc preview URLs', () => {
it('round-trips a nested relative path', () => {
const url = buildDocPreviewUrl(GRANT, 'assets/logo.png')
expect(url).toBe(`orca-preview://${GRANT}/assets/logo.png`)
expect(parseDocPreviewUrl(url)).toEqual({ grantId: GRANT, relativePath: 'assets/logo.png' })
})
it('encodes characters that would otherwise split the URL', () => {
const url = buildDocPreviewUrl(GRANT, 'a b/c#d?e.html')
expect(url).toBe(`orca-preview://${GRANT}/a%20b/c%23d%3Fe.html`)
expect(parseDocPreviewUrl(url)).toEqual({ grantId: GRANT, relativePath: 'a b/c#d?e.html' })
})
it('normalizes backslashes into path segments so a Windows path cannot smuggle one segment', () => {
expect(parseDocPreviewUrl(buildDocPreviewUrl(GRANT, 'assets\\logo.png'))).toEqual({
grantId: GRANT,
relativePath: 'assets/logo.png'
})
})
it('reports an empty relative path for a root request', () => {
expect(parseDocPreviewUrl(`orca-preview://${GRANT}/`)).toEqual({
grantId: GRANT,
relativePath: ''
})
})
it('rejects malformed grant ids and other schemes', () => {
expect(parseDocPreviewUrl('orca-preview://SHORT/index.html')).toBeNull()
expect(parseDocPreviewUrl(`orca-preview://${'g'.repeat(32)}/index.html`)).toBeNull()
expect(parseDocPreviewUrl(`https://${GRANT}/index.html`)).toBeNull()
expect(parseDocPreviewUrl('not a url')).toBeNull()
})
it('rejects an undecodable percent sequence rather than passing raw bytes through', () => {
expect(parseDocPreviewUrl(`orca-preview://${GRANT}/%E0%A4%A.html`)).toBeNull()
})
})