Files
windmill/frontend/src/lib/components/instanceSettingsMarkedLabel.test.ts
T
Ruben Fiszel 2d2cdb7a99 allowlist resource_type and escape fuzzy-search highlights (#10509)
* 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
2026-08-04 17:07:56 +02:00

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 &amp; B — category', label.length)).toBe('A &amp; 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('&quot;q&quot; &amp; &lt;x&gt; — trailing', label.length)
expect(out).toBe('&quot;q&quot; &amp; &lt;x&gt;')
expect(out.endsWith(';')).toBe(true)
})
})