mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-11 00:06:06 +00:00
* fix: allowlist resource_type and escape search highlights * fix: bound path length and keep marked-label offsets entity-aware * fix: match postgres word-char semantics and drop double-escaping * fix: sanitize db constraint and rls errors instead of relying on the regex
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { extractMarkedLabel } from './instanceSettings'
|
|
|
|
// SearchItems escapes the haystack before highlighting, so `marked` carries
|
|
// entities where the label had `& < > " '`. The offset walk counts unescaped
|
|
// characters, so an entity must advance it by one — otherwise the label is
|
|
// truncated early and can be sliced mid-entity.
|
|
describe('extractMarkedLabel', () => {
|
|
it('counts an escaped character as one, not as its entity length', () => {
|
|
const label = 'A & B'
|
|
expect(extractMarkedLabel('A & B — category', label.length)).toBe('A & B')
|
|
})
|
|
|
|
it('keeps the mark wrapper and stops at the label boundary', () => {
|
|
const label = 'Base URL'
|
|
expect(extractMarkedLabel('<mark>Base</mark> URL — general', label.length)).toBe(
|
|
'<mark>Base</mark> URL'
|
|
)
|
|
})
|
|
|
|
it('never slices an entity in half', () => {
|
|
const label = '"q" & <x>'
|
|
const out = extractMarkedLabel('"q" & <x> — trailing', label.length)
|
|
expect(out).toBe('"q" & <x>')
|
|
expect(out.endsWith(';')).toBe(true)
|
|
})
|
|
})
|