Skip to content

Commit 1169e94

Browse files
committed
fixup
1 parent 9acb99f commit 1169e94

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

lib/fetch/body.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ function extractBody (object, keepalive = false) {
7575
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
7676

7777
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
78-
const escape = str => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22')
79-
const normalizeLinefeeds = value => value.replace(/\r?\n|\r/g, '\r\n')
78+
const escape = (str) =>
79+
str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22')
80+
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, '\r\n')
8081

8182
// Set action to this step: run the multipart/form-data
8283
// encoding algorithm, with object’s entry list and UTF-8.
@@ -94,7 +95,8 @@ function extractBody (object, keepalive = false) {
9495
yield enc.encode(
9596
prefix +
9697
`; name="${escape(normalizeLinefeeds(name))}"` +
97-
(value.filename ? `; filename="${escape(value.filename)}"` : '') + '\r\n' +
98+
(value.filename ? `; filename="${escape(value.filename)}"` : '') +
99+
'\r\n' +
98100
`Content-Type: ${
99101
value.type || 'application/octet-stream'
100102
}\r\n\r\n`
@@ -149,9 +151,8 @@ function extractBody (object, keepalive = false) {
149151
)
150152
}
151153

152-
stream = object instanceof ReadableStream
153-
? object
154-
: ReadableStreamFrom(object)
154+
stream =
155+
object instanceof ReadableStream ? object : ReadableStreamFrom(object)
155156
} else {
156157
// TODO: byte sequence?
157158
// TODO: scalar value string?

lib/fetch/request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
const { extractBody, mixinBody, cloneBody } = require('./body')
66
const { Headers, fill: fillHeaders, HeadersList } = require('./headers')
77
const util = require('../core/util')
8-
const { isValidHTTPToken, EnvironmentSettingsObject, toUSVString } = require('./util')
8+
const {
9+
isValidHTTPToken,
10+
EnvironmentSettingsObject,
11+
toUSVString
12+
} = require('./util')
913
const {
1014
forbiddenMethods,
1115
corsSafeListedMethods,

lib/fetch/util.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { redirectStatus } = require('./constants')
44
const { performance } = require('perf_hooks')
5+
const nodeUtil = require('util')
56

67
let ReadableStream
78

@@ -280,23 +281,6 @@ function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) {
280281
// TODO
281282
}
282283

283-
function _toUSVString (val) {
284-
// TODO: This is internal to node core...
285-
return val
286-
}
287-
288-
const unpairedSurrogateRe =
289-
/(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/
290-
291-
// https://github.com/nodejs/node/blob/7ca38f05a023666274569343f128c5aed81599f3/lib/internal/url.js#L144
292-
function toUSVString (val) {
293-
const str = `${val}`
294-
// As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are
295-
// slower than `unpairedSurrogateRe.exec()`.
296-
const match = unpairedSurrogateRe.exec(str)
297-
return match ? _toUSVString(str, match.index) : str
298-
}
299-
300284
class ServiceWorkerGlobalScope {} // dummy
301285
class Window {} // dummy
302286
class EnvironmentSettingsObject {} // dummy
@@ -307,7 +291,7 @@ module.exports = {
307291
ServiceWorkerGlobalScope,
308292
Window,
309293
EnvironmentSettingsObject,
310-
toUSVString,
294+
toUSVString: nodeUtil.toUSVString || ((val) => `${val}`),
311295
tryUpgradeRequestToAPotentiallyTrustworthyURL,
312296
coarsenedSharedCurrentTime,
313297
matchRequestIntegrity,

0 commit comments

Comments
 (0)