Skip to content

Commit

Permalink
chore: removed unused escapeFormDataName (#3084)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Apr 10, 2024
1 parent 1f70214 commit 48af032
Showing 1 changed file with 2 additions and 40 deletions.
42 changes: 2 additions & 40 deletions lib/web/fetch/formdata-parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { toUSVString, isUSVString, bufferToLowerCasedHeaderName } = require('../../core/util')
const { isUSVString, bufferToLowerCasedHeaderName } = require('../../core/util')
const { utf8DecodeBytes } = require('./util')
const { HTTP_TOKEN_CODEPOINTS, isomorphicDecode } = require('./data-url')
const { isFileLike, File: UndiciFile } = require('./file')
Expand Down Expand Up @@ -60,43 +60,6 @@ function validateBoundary (boundary) {
return true
}

/**
* @see https://andreubotella.github.io/multipart-form-data/#escape-a-multipart-form-data-name
* @param {string} name
* @param {string} [encoding='utf-8']
* @param {boolean} [isFilename=false]
*/
function escapeFormDataName (name, encoding = 'utf-8', isFilename = false) {
// 1. If isFilename is true:
if (isFilename) {
// 1.1. Set name to the result of converting name into a scalar value string.
name = toUSVString(name)
} else {
// 2. Otherwise:

// 2.1. Assert: name is a scalar value string.
assert(isUSVString(name))

// 2.2. Replace every occurrence of U+000D (CR) not followed by U+000A (LF),
// and every occurrence of U+000A (LF) not preceded by U+000D (CR), in
// name, by a string consisting of U+000D (CR) and U+000A (LF).
name = name.replace(/\r\n?|\r?\n/g, '\r\n')
}

// 3. Let encoded be the result of encoding name with encoding.
assert(Buffer.isEncoding(encoding))

// 4. Replace every 0x0A (LF) bytes in encoded with the byte sequence `%0A`,
// 0x0D (CR) with `%0D` and 0x22 (") with `%22`.
name = name
.replace(/\n/g, '%0A')
.replace(/\r/g, '%0D')
.replace(/"/g, '%22')

// 5. Return encoded.
return Buffer.from(name, encoding) // encoded
}

/**
* @see https://andreubotella.github.io/multipart-form-data/#multipart-form-data-parser
* @param {Buffer} input
Expand Down Expand Up @@ -497,6 +460,5 @@ function bufferStartsWith (buffer, start, position) {

module.exports = {
multipartFormDataParser,
validateBoundary,
escapeFormDataName
validateBoundary
}

0 comments on commit 48af032

Please sign in to comment.