char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
877 B23 linesraw
1import {
2	KEY_VALUE_PAIR_KEY_MAX_LENGTH,
3	KEY_VALUE_PAIR_UNSAFE_KEY_RE,
4	KEY_VALUE_PAIR_UNSAFE_VALUE_RE,
5	KEY_VALUE_PAIR_VALUE_MAX_LENGTH
6} from '$lib/constants';
7
8/**
9 * Strip control characters unsafe in identifier/header-name contexts and cap length.
10 * Removes all C0 controls (including TAB) and DEL.
11 */
12export function sanitizeKeyValuePairKey(raw: string): string {
13	return raw.replace(KEY_VALUE_PAIR_UNSAFE_KEY_RE, '').slice(0, KEY_VALUE_PAIR_KEY_MAX_LENGTH);
14}
15
16/**
17 * Strip control characters that enable header injection; allow TAB; cap length.
18 * Removes null bytes, CR/LF and other C0/DEL controls while keeping TAB (\x09),
19 * which is a valid header-value continuation character per RFC 7230.
20 */
21export function sanitizeKeyValuePairValue(raw: string): string {
22	return raw.replace(KEY_VALUE_PAIR_UNSAFE_VALUE_RE, '').slice(0, KEY_VALUE_PAIR_VALUE_MAX_LENGTH);
23}