{"version":3,"file":"formdata-parser.mjs","sources":["../../../../lib/web/fetch/formdata-parser.js"],"sourcesContent":["'use strict'\n\nconst { bufferToLowerCasedHeaderName } = require('../../core/util')\nconst { HTTP_TOKEN_CODEPOINTS } = require('./data-url')\nconst { makeEntry } = require('./formdata')\nconst { webidl } = require('../webidl')\nconst assert = require('node:assert')\nconst { isomorphicDecode } = require('../infra')\n\nconst dd = Buffer.from('--')\nconst decoder = new TextDecoder()\nconst decoderIgnoreBOM = new TextDecoder('utf-8', { ignoreBOM: true })\n\n/**\n * @param {string} chars\n */\nfunction isAsciiString (chars) {\n  for (let i = 0; i < chars.length; ++i) {\n    if ((chars.charCodeAt(i) & ~0x7F) !== 0) {\n      return false\n    }\n  }\n  return true\n}\n\n/**\n * @see https://andreubotella.github.io/multipart-form-data/#multipart-form-data-boundary\n * @param {string} boundary\n */\nfunction validateBoundary (boundary) {\n  const length = boundary.length\n\n  // - its length is greater or equal to 27 and lesser or equal to 70, and\n  if (length < 27 || length > 70) {\n    return false\n  }\n\n  // - it is composed by bytes in the ranges 0x30 to 0x39, 0x41 to 0x5A, or\n  //   0x61 to 0x7A, inclusive (ASCII alphanumeric), or which are 0x27 ('),\n  //   0x2D (-) or 0x5F (_).\n  for (let i = 0; i < length; ++i) {\n    const cp = boundary.charCodeAt(i)\n\n    if (!(\n      (cp >= 0x30 && cp <= 0x39) ||\n      (cp >= 0x41 && cp <= 0x5a) ||\n      (cp >= 0x61 && cp <= 0x7a) ||\n      cp === 0x27 ||\n      cp === 0x2d ||\n      cp === 0x5f\n    )) {\n      return false\n    }\n  }\n\n  return true\n}\n\n/**\n * @see https://andreubotella.github.io/multipart-form-data/#multipart-form-data-parser\n * @param {Buffer} input\n * @param {ReturnType<import('./data-url')['parseMIMEType']>} mimeType\n */\nfunction multipartFormDataParser (input, mimeType) {\n  // 1. Assert: mimeType’s essence is \"multipart/form-data\".\n  assert(mimeType !== 'failure' && mimeType.essence === 'multipart/form-data')\n\n  const boundaryString = mimeType.parameters.get('boundary')\n\n  // 2. If mimeType’s parameters[\"boundary\"] does not exist, return failure.\n  //    Otherwise, let boundary be the result of UTF-8 decoding mimeType’s\n  //    parameters[\"boundary\"].\n  if (boundaryString === undefined) {\n    throw parsingError('missing boundary in content-type header')\n  }\n\n  const boundary = Buffer.from(`--${boundaryString}`, 'utf8')\n\n  // 3. Let entry list be an empty entry list.\n  const entryList = []\n\n  // 4. Let position be a pointer to a byte in input, initially pointing at\n  //    the first byte.\n  const position = { position: 0 }\n\n  // Note: Per RFC 2046 Section 5.1.1, we must ignore anything before the\n  // first boundary delimiter line (preamble). Search for the first boundary.\n  const firstBoundaryIndex = input.indexOf(boundary)\n\n  if (firstBoundaryIndex === -1) {\n    throw parsingError('no boundary found in multipart body')\n  }\n\n  // Start parsing from the first boundary, ignoring any preamble\n  position.position = firstBoundaryIndex\n\n  // 5. While true:\n  while (true) {\n    // 5.1. If position points to a sequence of bytes starting with 0x2D 0x2D\n    //      (`--`) followed by boundary, advance position by 2 + the length of\n    //      boundary. Otherwise, return failure.\n    // Note: boundary is padded with 2 dashes already, no need to add 2.\n    if (input.subarray(position.position, position.position + boundary.length).equals(boundary)) {\n      position.position += boundary.length\n    } else {\n      throw parsingError('expected a value starting with -- and the boundary')\n    }\n\n    // 5.2. If position points to the sequence of bytes 0x2D 0x2D 0x0D 0x0A\n    //      (`--` followed by CR LF) followed by the end of input, return entry list.\n    // Note: Per RFC 2046 Section 5.1.1, we must ignore anything after the\n    // final boundary delimiter (epilogue). Check for -- or --CRLF and return\n    // regardless of what follows.\n    if (bufferStartsWith(input, dd, position)) {\n      // Found closing boundary delimiter (--), ignore any epilogue\n      return entryList\n    }\n\n    // 5.3. If position does not point to a sequence of bytes starting with 0x0D\n    //      0x0A (CR LF), return failure.\n    if (input[position.position] !== 0x0d || input[position.position + 1] !== 0x0a) {\n      throw parsingError('expected CRLF')\n    }\n\n    // 5.4. Advance position by 2. (This skips past the newline.)\n    position.position += 2\n\n    // 5.5. Let name, filename and contentType be the result of parsing\n    //      multipart/form-data headers on input and position, if the result\n    //      is not failure. Otherwise, return failure.\n    const result = parseMultipartFormDataHeaders(input, position)\n\n    let { name, filename, contentType, encoding } = result\n\n    // 5.6. Advance position by 2. (This skips past the empty line that marks\n    //      the end of the headers.)\n    position.position += 2\n\n    // 5.7. Let body be the empty byte sequence.\n    let body\n\n    // 5.8. Body loop: While position is not past the end of input:\n    // TODO: the steps here are completely wrong\n    {\n      const boundaryIndex = input.indexOf(boundary.subarray(2), position.position)\n\n      if (boundaryIndex === -1) {\n        throw parsingError('expected boundary after body')\n      }\n\n      body = input.subarray(position.position, boundaryIndex - 4)\n\n      position.position += body.length\n\n      // Note: position must be advanced by the body's length before being\n      // decoded, otherwise the parsing will fail.\n      if (encoding === 'base64') {\n        body = Buffer.from(body.toString(), 'base64')\n      }\n    }\n\n    // 5.9. If position does not point to a sequence of bytes starting with\n    //      0x0D 0x0A (CR LF), return failure. Otherwise, advance position by 2.\n    if (input[position.position] !== 0x0d || input[position.position + 1] !== 0x0a) {\n      throw parsingError('expected CRLF')\n    } else {\n      position.position += 2\n    }\n\n    // 5.10. If filename is not null:\n    let value\n\n    if (filename !== null) {\n      // 5.10.1. If contentType is null, set contentType to \"text/plain\".\n      contentType ??= 'text/plain'\n\n      // 5.10.2. If contentType is not an ASCII string, set contentType to the empty string.\n\n      // Note: `buffer.isAscii` can be used at zero-cost, but converting a string to a buffer is a high overhead.\n      // Content-Type is a relatively small string, so it is faster to use `String#charCodeAt`.\n      if (!isAsciiString(contentType)) {\n        contentType = ''\n      }\n\n      // 5.10.3. Let value be a new File object with name filename, type contentType, and body body.\n      value = new File([body], filename, { type: contentType })\n    } else {\n      // 5.11. Otherwise:\n\n      // 5.11.1. Let value be the UTF-8 decoding without BOM of body.\n      value = decoderIgnoreBOM.decode(Buffer.from(body))\n    }\n\n    // 5.12. Assert: name is a scalar value string and value is either a scalar value string or a File object.\n    assert(webidl.is.USVString(name))\n    assert((typeof value === 'string' && webidl.is.USVString(value)) || webidl.is.File(value))\n\n    // 5.13. Create an entry with name and value, and append it to entry list.\n    entryList.push(makeEntry(name, value, filename))\n  }\n}\n\n/**\n * Parses content-disposition attributes (e.g., name=\"value\" or filename*=utf-8''encoded)\n * @param {Buffer} input\n * @param {{ position: number }} position\n * @returns {{ name: string, value: string, extended: boolean } | null}\n */\nfunction parseContentDispositionAttribute (input, position) {\n  // Skip leading semicolon and whitespace\n  if (input[position.position] === 0x3b /* ; */) {\n    position.position++\n  }\n\n  // Skip whitespace\n  collectASequenceOfBytes(\n    (char) => char === 0x20 || char === 0x09,\n    input,\n    position\n  )\n\n  // Collect attribute name (token characters)\n  const attributeName = collectASequenceOfBytes(\n    (char) => isToken(char) && char !== 0x3d && char !== 0x2a, // not = or *\n    input,\n    position\n  )\n\n  if (attributeName.length === 0) {\n    return null\n  }\n\n  const attrNameStr = attributeName.toString('ascii').toLowerCase()\n\n  // Check for extended notation (attribute*)\n  const isExtended = input[position.position] === 0x2a /* * */\n  if (isExtended) {\n    position.position++ // skip *\n  }\n\n  // Expect = sign\n  if (input[position.position] !== 0x3d /* = */) {\n    return null\n  }\n  position.position++ // skip =\n\n  // Skip whitespace\n  collectASequenceOfBytes(\n    (char) => char === 0x20 || char === 0x09,\n    input,\n    position\n  )\n\n  let value\n\n  if (isExtended) {\n    // Extended attribute format: charset'language'encoded-value\n    const headerValue = collectASequenceOfBytes(\n      (char) => char !== 0x20 && char !== 0x0d && char !== 0x0a && char !== 0x3b, // not space, CRLF, or ;\n      input,\n      position\n    )\n\n    // Check for utf-8'' prefix (case insensitive)\n    if (\n      (headerValue[0] !== 0x75 && headerValue[0] !== 0x55) || // u or U\n      (headerValue[1] !== 0x74 && headerValue[1] !== 0x54) || // t or T\n      (headerValue[2] !== 0x66 && headerValue[2] !== 0x46) || // f or F\n      headerValue[3] !== 0x2d || // -\n      headerValue[4] !== 0x38 // 8\n    ) {\n      throw parsingError('unknown encoding, expected utf-8\\'\\'')\n    }\n\n    // Skip utf-8'' and decode the rest\n    value = decodeURIComponent(decoder.decode(headerValue.subarray(7)))\n  } else if (input[position.position] === 0x22 /* \" */) {\n    // Quoted string\n    position.position++ // skip opening quote\n\n    const quotedValue = collectASequenceOfBytes(\n      (char) => char !== 0x0a && char !== 0x0d && char !== 0x22, // not LF, CR, or \"\n      input,\n      position\n    )\n\n    if (input[position.position] !== 0x22) {\n      throw parsingError('Closing quote not found')\n    }\n    position.position++ // skip closing quote\n\n    value = decoder.decode(quotedValue)\n      .replace(/%0A/ig, '\\n')\n      .replace(/%0D/ig, '\\r')\n      .replace(/%22/g, '\"')\n  } else {\n    // Token value (no quotes)\n    const tokenValue = collectASequenceOfBytes(\n      (char) => isToken(char) && char !== 0x3b, // not ;\n      input,\n      position\n    )\n\n    value = decoder.decode(tokenValue)\n  }\n\n  return { name: attrNameStr, value, extended: isExtended }\n}\n\n/**\n * @see https://andreubotella.github.io/multipart-form-data/#parse-multipart-form-data-headers\n * @param {Buffer} input\n * @param {{ position: number }} position\n */\nfunction parseMultipartFormDataHeaders (input, position) {\n  // 1. Let name, filename and contentType be null.\n  let name = null\n  let filename = null\n  let contentType = null\n  let encoding = null\n\n  // 2. While true:\n  while (true) {\n    // 2.1. If position points to a sequence of bytes starting with 0x0D 0x0A (CR LF):\n    if (input[position.position] === 0x0d && input[position.position + 1] === 0x0a) {\n      // 2.1.1. If name is null, return failure.\n      if (name === null) {\n        throw parsingError('header name is null')\n      }\n\n      // 2.1.2. Return name, filename and contentType.\n      return { name, filename, contentType, encoding }\n    }\n\n    // 2.2. Let header name be the result of collecting a sequence of bytes that are\n    //      not 0x0A (LF), 0x0D (CR) or 0x3A (:), given position.\n    let headerName = collectASequenceOfBytes(\n      (char) => char !== 0x0a && char !== 0x0d && char !== 0x3a,\n      input,\n      position\n    )\n\n    // 2.3. Remove any HTTP tab or space bytes from the start or end of header name.\n    headerName = removeChars(headerName, true, true, (char) => char === 0x9 || char === 0x20)\n\n    // 2.4. If header name does not match the field-name token production, return failure.\n    if (!HTTP_TOKEN_CODEPOINTS.test(headerName.toString())) {\n      throw parsingError('header name does not match the field-name token production')\n    }\n\n    // 2.5. If the byte at position is not 0x3A (:), return failure.\n    if (input[position.position] !== 0x3a) {\n      throw parsingError('expected :')\n    }\n\n    // 2.6. Advance position by 1.\n    position.position++\n\n    // 2.7. Collect a sequence of bytes that are HTTP tab or space bytes given position.\n    //      (Do nothing with those bytes.)\n    collectASequenceOfBytes(\n      (char) => char === 0x20 || char === 0x09,\n      input,\n      position\n    )\n\n    // 2.8. Byte-lowercase header name and switch on the result:\n    switch (bufferToLowerCasedHeaderName(headerName)) {\n      case 'content-disposition': {\n        name = filename = null\n        // Track whether filename was set from the extended (RFC 5987) form so\n        // a subsequent legacy `filename` attribute does not override it.\n        let filenameIsExtended = false\n\n        // Collect the disposition type (should be \"form-data\")\n        const dispositionType = collectASequenceOfBytes(\n          (char) => isToken(char),\n          input,\n          position\n        )\n\n        if (dispositionType.toString('ascii').toLowerCase() !== 'form-data') {\n          throw parsingError('expected form-data for content-disposition header')\n        }\n\n        // Parse attributes recursively until CRLF\n        while (\n          position.position < input.length &&\n          (input[position.position] !== 0x0d ||\n          input[position.position + 1] !== 0x0a)\n        ) {\n          const attribute = parseContentDispositionAttribute(input, position)\n\n          if (!attribute) {\n            break\n          }\n\n          if (attribute.name === 'name') {\n            name = attribute.value\n          } else if (attribute.name === 'filename') {\n            // Per RFC 5987 §4.1, when both legacy and extended forms of the\n            // same parameter are present, the extended (filename*) form takes\n            // precedence regardless of the order they appear in.\n            if (attribute.extended) {\n              filename = attribute.value\n              filenameIsExtended = true\n            } else if (!filenameIsExtended) {\n              filename = attribute.value\n            }\n          }\n        }\n\n        if (name === null) {\n          throw parsingError('name attribute is required in content-disposition header')\n        }\n\n        break\n      }\n      case 'content-type': {\n        // 1. Let header value be the result of collecting a sequence of bytes that are\n        //    not 0x0A (LF) or 0x0D (CR), given position.\n        let headerValue = collectASequenceOfBytes(\n          (char) => char !== 0x0a && char !== 0x0d,\n          input,\n          position\n        )\n\n        // 2. Remove any HTTP tab or space bytes from the end of header value.\n        headerValue = removeChars(headerValue, false, true, (char) => char === 0x9 || char === 0x20)\n\n        // 3. Set contentType to the isomorphic decoding of header value.\n        contentType = isomorphicDecode(headerValue)\n\n        break\n      }\n      case 'content-transfer-encoding': {\n        let headerValue = collectASequenceOfBytes(\n          (char) => char !== 0x0a && char !== 0x0d,\n          input,\n          position\n        )\n\n        headerValue = removeChars(headerValue, false, true, (char) => char === 0x9 || char === 0x20)\n\n        encoding = isomorphicDecode(headerValue)\n\n        break\n      }\n      default: {\n        // Collect a sequence of bytes that are not 0x0A (LF) or 0x0D (CR), given position.\n        // (Do nothing with those bytes.)\n        collectASequenceOfBytes(\n          (char) => char !== 0x0a && char !== 0x0d,\n          input,\n          position\n        )\n      }\n    }\n\n    // 2.9. If position does not point to a sequence of bytes starting with 0x0D 0x0A\n    //      (CR LF), return failure. Otherwise, advance position by 2 (past the newline).\n    if (input[position.position] !== 0x0d || input[position.position + 1] !== 0x0a) {\n      throw parsingError('expected CRLF')\n    } else {\n      position.position += 2\n    }\n  }\n}\n\n/**\n * @param {(char: number) => boolean} condition\n * @param {Buffer} input\n * @param {{ position: number }} position\n */\nfunction collectASequenceOfBytes (condition, input, position) {\n  let start = position.position\n\n  while (start < input.length && condition(input[start])) {\n    ++start\n  }\n\n  return input.subarray(position.position, (position.position = start))\n}\n\n/**\n * @param {Buffer} buf\n * @param {boolean} leading\n * @param {boolean} trailing\n * @param {(charCode: number) => boolean} predicate\n * @returns {Buffer}\n */\nfunction removeChars (buf, leading, trailing, predicate) {\n  let lead = 0\n  let trail = buf.length - 1\n\n  if (leading) {\n    while (lead < buf.length && predicate(buf[lead])) lead++\n  }\n\n  if (trailing) {\n    while (trail > 0 && predicate(buf[trail])) trail--\n  }\n\n  return lead === 0 && trail === buf.length - 1 ? buf : buf.subarray(lead, trail + 1)\n}\n\n/**\n * Checks if {@param buffer} starts with {@param start}\n * @param {Buffer} buffer\n * @param {Buffer} start\n * @param {{ position: number }} position\n */\nfunction bufferStartsWith (buffer, start, position) {\n  if (buffer.length < start.length) {\n    return false\n  }\n\n  for (let i = 0; i < start.length; i++) {\n    if (start[i] !== buffer[position.position + i]) {\n      return false\n    }\n  }\n\n  return true\n}\n\nfunction parsingError (cause) {\n  return new TypeError('Failed to parse body as FormData.', { cause: new TypeError(cause) })\n}\n\n/**\n * CTL            = <any US-ASCII control character\n *                  (octets 0 - 31) and DEL (127)>\n * @param {number} char\n */\nfunction isCTL (char) {\n  return char <= 0x1f || char === 0x7f\n}\n\n/**\n * tspecials :=  \"(\" / \")\" / \"<\" / \">\" / \"@\" /\n *                \",\" / \";\" / \":\" / \"\\\" / <\">\n *                \"/\" / \"[\" / \"]\" / \"?\" / \"=\"\n *                ; Must be in quoted-string,\n *                ; to use within parameter values\n * @param {number} char\n */\nfunction isTSpecial (char) {\n  return (\n    char === 0x28 || // (\n    char === 0x29 || // )\n    char === 0x3c || // <\n    char === 0x3e || // >\n    char === 0x40 || // @\n    char === 0x2c || // ,\n    char === 0x3b || // ;\n    char === 0x3a || // :\n    char === 0x5c || // \\\n    char === 0x22 || // \"\n    char === 0x2f || // /\n    char === 0x5b || // [\n    char === 0x5d || // ]\n    char === 0x3f || // ?\n    char === 0x3d    // +\n  )\n}\n\n/**\n * token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,\n *          or tspecials>\n * @param {number} char\n */\nfunction isToken (char) {\n  return (\n    char <= 0x7f &&  // ascii\n    char !== 0x20 && // space\n    char !== 0x09 &&\n    !isCTL(char) &&\n    !isTSpecial(char)\n  )\n}\n\nmodule.exports = {\n  multipartFormDataParser,\n  validateBoundary\n}\n"],"names":["bufferToLowerCasedHeaderName","require$$0","HTTP_TOKEN_CODEPOINTS","require$$1","makeEntry","require$$2","webidl","require$$3","assert","require$$4","isomorphicDecode","require$$5","dd","Buffer","from","decoder","TextDecoder","decoderIgnoreBOM","ignoreBOM","isAsciiString","chars","i","length","charCodeAt","parseContentDispositionAttribute","input","position","collectASequenceOfBytes","char","attributeName","isToken","attrNameStr","toString","toLowerCase","isExtended","value","headerValue","parsingError","decodeURIComponent","decode","subarray","quotedValue","replace","tokenValue","name","extended","parseMultipartFormDataHeaders","filename","contentType","encoding","headerName","removeChars","test","filenameIsExtended","attribute","condition","start","buf","leading","trailing","predicate","lead","trail","bufferStartsWith","buffer","cause","TypeError","isCTL","isTSpecial","formdataParser","multipartFormDataParser","mimeType","essence","boundaryString","parameters","get","undefined","boundary","entryList","firstBoundaryIndex","indexOf","equals","result","body","boundaryIndex","File","type","is","USVString","push","validateBoundary","cp"],"mappings":"8fAEA,MAAMA,8BAAmCC,MACnCC,uBAA4BC,kBAC5BC,WAAgBC,mBAChBC,QAAaC,gBACbC,OAASC,YACTC,kBAAuBC,eAEvBC,GAAKC,OAAOC,KAAK,MACjBC,QAAU,IAAIC,YACdC,iBAAmB,IAAID,YAAY,QAAS,CAAEE,WAAW;;;;AAK/D,SAASC,cAAeC,OACtB,IAAK,IAAIC,EAAI,EAAGA,EAAID,MAAME,SAAUD,EAClC,IAA2B,IAAtBD,MAAMG,WAAWF,GACpB,OAAO,EAGX,OAAO,CACT;;;;;;;;;;;AAyLA,SAASG,iCAAkCC,MAAOC;;AAEf,YAA7BD,MAAMC,SAASA,WACjBA,SAASA;;AAIXC,wBACGC,MAAkB,KAATA,MAA0B,IAATA,KAC3BH,MACAC;;AAIF,MAAMG,cAAgBF,wBACnBC,MAASE,QAAQF,OAAkB,KAATA,MAA0B,KAATA;AAC5CH,MACAC,UAGF,GAA6B,IAAzBG,cAAcP,OAChB,OAAO,KAGT,MAAMS,YAAcF,cAAcG,SAAS,SAASC,cAG9CC,WAA0C,KAA7BT,MAAMC,SAASA;;;AAMlC;AALIQ,YACFR,SAASA,WAIsB,YAA7BD,MAAMC,SAASA,UACjB,OAAO,KAWT,IAAIS,MAEJ,GAXAT,SAASA;;AAGTC,wBACGC,MAAkB,KAATA,MAA0B,IAATA,KAC3BH,MACAC,UAKEQ,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