(val: string, replacement?: string | Replacement)
| 80 | * @param {String|Function} replacement - can be `function(char)` |
| 81 | */ |
| 82 | export function replaceInvalidHttpHeaderChar(val: string, replacement?: string | Replacement) { |
| 83 | replacement = replacement || ' '; |
| 84 | let invalid = false; |
| 85 | |
| 86 | if (!val || typeof val !== 'string') { |
| 87 | return { |
| 88 | val, |
| 89 | invalid, |
| 90 | }; |
| 91 | } |
| 92 | |
| 93 | let chars: string[] | undefined; |
| 94 | for (let i = 0; i < val.length; ++i) { |
| 95 | if (!validHdrChars[val.charCodeAt(i)]) { |
| 96 | // delay create chars |
| 97 | chars = chars || val.split(''); |
| 98 | if (typeof replacement === 'function') { |
| 99 | chars[i] = replacement(chars[i]); |
| 100 | } else { |
| 101 | chars[i] = replacement; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (chars) { |
| 107 | val = chars.join(''); |
| 108 | invalid = true; |
| 109 | } |
| 110 | |
| 111 | return { |
| 112 | val, |
| 113 | invalid, |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Detect invalid http header characters in a string |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…