char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1import { 2KEY_VALUE_PAIR_KEY_MAX_LENGTH , 3KEY_VALUE_PAIR_UNSAFE_KEY_RE , 4KEY_VALUE_PAIR_UNSAFE_VALUE_RE , 5KEY_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 { 13return 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 { 22return raw . replace ( KEY_VALUE_PAIR_UNSAFE_VALUE_RE , '' ). slice ( 0 , KEY_VALUE_PAIR_VALUE_MAX_LENGTH ); 23}