diff --git a/lib/fetch/body.js b/lib/fetch/body.js index 199485eaa10..e5c4b222d67 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -75,8 +75,9 @@ function extractBody (object, keepalive = false) { const prefix = `--${boundary}\r\nContent-Disposition: form-data` /*! formdata-polyfill. MIT License. Jimmy Wärting */ - const escape = str => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22') - const normalizeLinefeeds = value => value.replace(/\r?\n|\r/g, '\r\n') + const escape = (str) => + str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22') + const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n') // Set action to this step: run the multipart/form-data // encoding algorithm, with object’s entry list and UTF-8. @@ -94,7 +95,8 @@ function extractBody (object, keepalive = false) { yield enc.encode( prefix + `; name="${escape(normalizeLinefeeds(name))}"` + - (value.filename ? `; filename="${escape(value.filename)}"` : '') + '\r\n' + + (value.filename ? `; filename="${escape(value.filename)}"` : '') + + '\r\n' + `Content-Type: ${ value.type || 'application/octet-stream' }\r\n\r\n` @@ -149,9 +151,8 @@ function extractBody (object, keepalive = false) { ) } - stream = object instanceof ReadableStream - ? object - : ReadableStreamFrom(object) + stream = + object instanceof ReadableStream ? object : ReadableStreamFrom(object) } else { // TODO: byte sequence? // TODO: scalar value string? diff --git a/lib/fetch/request.js b/lib/fetch/request.js index c97438acc46..152d888f91b 100644 --- a/lib/fetch/request.js +++ b/lib/fetch/request.js @@ -5,7 +5,11 @@ const { extractBody, mixinBody, cloneBody } = require('./body') const { Headers, fill: fillHeaders, HeadersList } = require('./headers') const util = require('../core/util') -const { isValidHTTPToken, EnvironmentSettingsObject, toUSVString } = require('./util') +const { + isValidHTTPToken, + EnvironmentSettingsObject, + toUSVString +} = require('./util') const { forbiddenMethods, corsSafeListedMethods, diff --git a/lib/fetch/util.js b/lib/fetch/util.js index b39587ca363..fcf187e3a83 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -2,6 +2,7 @@ const { redirectStatus } = require('./constants') const { performance } = require('perf_hooks') +const nodeUtil = require('util') let ReadableStream @@ -280,23 +281,6 @@ function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) { // TODO } -function _toUSVString (val) { - // TODO: This is internal to node core... - return val -} - -const unpairedSurrogateRe = - /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/ - -// https://github.com/nodejs/node/blob/7ca38f05a023666274569343f128c5aed81599f3/lib/internal/url.js#L144 -function toUSVString (val) { - const str = `${val}` - // As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are - // slower than `unpairedSurrogateRe.exec()`. - const match = unpairedSurrogateRe.exec(str) - return match ? _toUSVString(str, match.index) : str -} - class ServiceWorkerGlobalScope {} // dummy class Window {} // dummy class EnvironmentSettingsObject {} // dummy @@ -307,7 +291,7 @@ module.exports = { ServiceWorkerGlobalScope, Window, EnvironmentSettingsObject, - toUSVString, + toUSVString: nodeUtil.toUSVString || ((val) => `${val}`), tryUpgradeRequestToAPotentiallyTrustworthyURL, coarsenedSharedCurrentTime, matchRequestIntegrity,