Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 19, 2021
1 parent 9acb99f commit 1169e94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
13 changes: 7 additions & 6 deletions lib/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ function extractBody (object, keepalive = false) {
const prefix = `--${boundary}\r\nContent-Disposition: form-data`

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
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.
Expand All @@ -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`
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 5 additions & 1 deletion lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 2 additions & 18 deletions lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { redirectStatus } = require('./constants')
const { performance } = require('perf_hooks')
const nodeUtil = require('util')

let ReadableStream

Expand Down Expand Up @@ -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
Expand All @@ -307,7 +291,7 @@ module.exports = {
ServiceWorkerGlobalScope,
Window,
EnvironmentSettingsObject,
toUSVString,
toUSVString: nodeUtil.toUSVString || ((val) => `${val}`),
tryUpgradeRequestToAPotentiallyTrustworthyURL,
coarsenedSharedCurrentTime,
matchRequestIntegrity,
Expand Down

0 comments on commit 1169e94

Please sign in to comment.