MCPcopy Index your code
hub / github.com/node-modules/utility / replaceInvalidHttpHeaderChar

Function replaceInvalidHttpHeaderChar

src/string.ts:82–115  ·  view source on GitHub ↗
(val: string, replacement?: string | Replacement)

Source from the content-addressed store, hash-verified

80 * @param {String|Function} replacement - can be `function(char)`
81 */
82export 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…