Files
windmill/frontend/src/lib/apiPathParams.test.ts
T
Ruben FiszelandClaude Opus 5.5 90c1361b73 fix(frontend): input handling cleanups
Path parameter encoding in the API client, lazy loading of inline dynamic select options, editor type acquisition paths and alert text rendering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 18:52:48 +00:00

31 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { encodePathParam } from './apiPathParams'
describe('encodePathParam', () => {
it('keeps slashes in path-like values', () => {
expect(encodePathParam('path', 'u/admin/my script')).toBe('u/admin/my%20script')
expect(encodePathParam('path', 'f/folder/a.b_c-d')).toBe('f/folder/a.b_c-d')
})
it('keeps query and fragment characters inside the segment', () => {
expect(encodePathParam('path', 'u/a/b?x=1#y')).toBe('u/a/b%3Fx=1%23y')
})
it('refuses dot segments, plain or percent-encoded', () => {
for (const v of ['u/../../jobs', '..', 'a/./b', 'a/%2e%2e/b', 'a/.%2E/b']) {
expect(() => encodePathParam('path', v)).toThrow()
}
expect(encodePathParam('path', 'a/...')).toBe('a/...')
})
it('encodes a workspace as one segment', () => {
expect(encodePathParam('workspace', 'acme-1_x')).toBe('acme-1_x')
expect(encodePathParam('workspace', 'acme/jobs/run?x=1')).toBe('acme%2Fjobs%2Frun%3Fx%3D1')
expect(() => encodePathParam('workspace', '..')).toThrow()
})
it('encodes percent signs so they are not decoded twice', () => {
expect(encodePathParam('path', 'a/%2e%2e%2fb')).toBe('a/%252e%252e%252fb')
})
})