MCPcopy Create free account
hub / github.com/nodejs/undici / parseContentDispositionAttribute

Function parseContentDispositionAttribute

lib/web/fetch/formdata-parser.js:209–308  ·  view source on GitHub ↗

* Parses content-disposition attributes (e.g., name="value" or filename*=utf-8''encoded) * @param {Buffer} input * @param {{ position: number }} position * @returns {{ name: string, value: string, extended: boolean } | null}

(input, position)

Source from the content-addressed store, hash-verified

207 * @returns {{ name: string, value: string, extended: boolean } | null}
208 */
209function parseContentDispositionAttribute (input, position) {
210 // Skip leading semicolon and whitespace
211 if (input[position.position] === 0x3b /* ; */) {
212 position.position++
213 }
214
215 // Skip whitespace
216 collectASequenceOfBytes(
217 (char) => char === 0x20 || char === 0x09,
218 input,
219 position
220 )
221
222 // Collect attribute name (token characters)
223 const attributeName = collectASequenceOfBytes(
224 (char) => isToken(char) && char !== 0x3d && char !== 0x2a, // not = or *
225 input,
226 position
227 )
228
229 if (attributeName.length === 0) {
230 return null
231 }
232
233 const attrNameStr = attributeName.toString('ascii').toLowerCase()
234
235 // Check for extended notation (attribute*)
236 const isExtended = input[position.position] === 0x2a /* * */
237 if (isExtended) {
238 position.position++ // skip *
239 }
240
241 // Expect = sign
242 if (input[position.position] !== 0x3d /* = */) {
243 return null
244 }
245 position.position++ // skip =
246
247 // Skip whitespace
248 collectASequenceOfBytes(
249 (char) => char === 0x20 || char === 0x09,
250 input,
251 position
252 )
253
254 let value
255
256 if (isExtended) {
257 // Extended attribute format: charset'language'encoded-value
258 const headerValue = collectASequenceOfBytes(
259 (char) => char !== 0x20 && char !== 0x0d && char !== 0x0a && char !== 0x3b, // not space, CRLF, or ;
260 input,
261 position
262 )
263
264 // Check for utf-8'' prefix (case insensitive)
265 if (
266 (headerValue[0] !== 0x75 && headerValue[0] !== 0x55) || // u or U

Callers 1

Calls 4

collectASequenceOfBytesFunction · 0.85
isTokenFunction · 0.85
parsingErrorFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected