Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce latin-1 encoding in source #2672

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions lib/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function extractBody (object, keepalive = false) {
stream = object
} else if (isBlobLike(object)) {
// 3. Otherwise, if object is a Blob object, set stream to the
// result of running objects get stream.
// result of running object's get stream.
stream = object.stream()
} else {
// 4. Otherwise, set stream to a new ReadableStream object, and set
Expand Down Expand Up @@ -87,7 +87,7 @@ function extractBody (object, keepalive = false) {
// See: https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/url.js#L490
// and https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/url.js#L1100

// Set source to the result of running the application/x-www-form-urlencoded serializer with objects list.
// Set source to the result of running the application/x-www-form-urlencoded serializer with object's list.
source = object.toString()

// Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
Expand All @@ -106,13 +106,13 @@ function extractBody (object, keepalive = false) {
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
const prefix = `--${boundary}\r\nContent-Disposition: form-data`

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
/*! formdata-polyfill. MIT License. Jimmy Warting <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')

// Set action to this step: run the multipart/form-data
// encoding algorithm, with objects entry list and UTF-8.
// encoding algorithm, with object's entry list and UTF-8.
// - This ensures that the body is immutable and can't be changed afterwords
// - That the content-length is calculated in advance.
// - And that all parts are pre-encoded and ready to be sent.
Expand Down Expand Up @@ -174,10 +174,10 @@ function extractBody (object, keepalive = false) {
// Set source to object.
source = object

// Set length to objects size.
// Set length to object's size.
length = object.size

// If objects type attribute is not the empty byte sequence, set
// If object's type attribute is not the empty byte sequence, set
// type to its value.
if (object.type) {
type = object.type
Expand All @@ -200,7 +200,7 @@ function extractBody (object, keepalive = false) {
}

// 11. If source is a byte sequence, then set action to a
// step that returns source and length to sources length.
// step that returns source and length to source's length.
if (typeof source === 'string' || util.isBuffer(source)) {
length = Buffer.byteLength(source)
}
Expand Down Expand Up @@ -272,14 +272,14 @@ function cloneBody (body) {

// https://fetch.spec.whatwg.org/#concept-body-clone

// 1. Let « out1, out2 » be the result of teeing bodys stream.
// 1. Let « out1, out2 » be the result of teeing body's stream.
const [out1, out2] = body.stream.tee()
const out2Clone = structuredClone(out2, { transfer: [out2] })
// This, for whatever reasons, unrefs out2Clone which allows
// the process to exit by itself.
const [, finalClone] = out2Clone.tee()

// 2. Set bodys stream to out1.
// 2. Set body's stream to out1.
body.stream = out1

// 3. Return a body whose stream is out2 and other members are copied from body.
Expand Down Expand Up @@ -325,7 +325,7 @@ function bodyMixinMethods (instance) {
// The blob() method steps are to return the result of
// running consume body with this and the following step
// given a byte sequence bytes: return a Blob whose
// contents are bytes and whose type attribute is thiss
// contents are bytes and whose type attribute is this's
// MIME type.
return specConsumeBody(this, (bytes) => {
let mimeType = bodyMimeType(this)
Expand Down Expand Up @@ -373,7 +373,7 @@ function bodyMixinMethods (instance) {

const mimeType = contentType !== null ? parseMIMEType(contentType) : 'failure'

// If mimeTypes essence is "multipart/form-data", then:
// If mimeType's essence is "multipart/form-data", then:
if (mimeType !== 'failure' && mimeType.essence === 'multipart/form-data') {
const headers = {}
for (const [key, value] of this.headers) headers[key] = value
Expand Down Expand Up @@ -433,7 +433,7 @@ function bodyMixinMethods (instance) {

return responseFormData
} else if (mimeType !== 'failure' && mimeType.essence === 'application/x-www-form-urlencoded') {
// Otherwise, if mimeTypes essence is "application/x-www-form-urlencoded", then:
// Otherwise, if mimeType's essence is "application/x-www-form-urlencoded", then:

// 1. Let entries be the result of parsing bytes.
let entries
Expand Down Expand Up @@ -522,15 +522,15 @@ async function specConsumeBody (object, convertBytesToJSValue, instance) {
}
}

// 5. If objects body is null, then run successSteps with an
// 5. If object's body is null, then run successSteps with an
// empty byte sequence.
if (object[kState].body == null) {
successSteps(new Uint8Array())
return promise.promise
}

// 6. Otherwise, fully read objects body given successSteps,
// errorSteps, and objects relevant global object.
// 6. Otherwise, fully read object's body given successSteps,
// errorSteps, and object's relevant global object.
await fullyReadBody(object[kState].body, successSteps, errorSteps)

// 7. Return promise.
Expand All @@ -541,7 +541,7 @@ async function specConsumeBody (object, convertBytesToJSValue, instance) {
function bodyUnusable (body) {
// An object including the Body interface mixin is
// said to be unusable if its body is non-null and
// its bodys stream is disturbed or locked.
// its body's stream is disturbed or locked.
return body != null && (body.stream.locked || util.isDisturbed(body.stream))
}

Expand All @@ -563,7 +563,7 @@ function utf8DecodeBytes (buffer) {
buffer = buffer.subarray(3)
}

// 3. Process a queue with an instance of UTF-8s
// 3. Process a queue with an instance of UTF-8's
// decoder, ioQueue, output, and "replacement".
const output = textDecoder.decode(buffer)

Expand Down
18 changes: 9 additions & 9 deletions lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const HTTP_QUOTED_STRING_TOKENS = /[\u0009|\u0020-\u007E|\u0080-\u00FF]/ // esli
// https://fetch.spec.whatwg.org/#data-url-processor
/** @param {URL} dataURL */
function dataURLProcessor (dataURL) {
// 1. Assert: dataURLs scheme is "data".
// 1. Assert: dataURL's scheme is "data".
assert(dataURL.protocol === 'data:')

// 2. Let input be the result of running the URL
Expand Down Expand Up @@ -145,7 +145,7 @@ function collectASequenceOfCodePoints (condition, input, position) {
// 1. Let result be the empty string.
let result = ''

// 2. While position doesnt point past the end of input and the
// 2. While position doesn't point past the end of input and the
// code point at position within input meets the condition condition:
while (position.position < input.length && condition(input[position.position])) {
// 1. Append that code point to the end of result.
Expand Down Expand Up @@ -410,8 +410,8 @@ function parseMIMEType (input) {
// - parameterName is not the empty string
// - parameterName solely contains HTTP token code points
// - parameterValue solely contains HTTP quoted-string token code points
// - mimeTypes parameters[parameterName] does not exist
// then set mimeTypes parameters[parameterName] to parameterValue.
// - mimeType's parameters[parameterName] does not exist
// then set mimeType's parameters[parameterName] to parameterValue.
if (
parameterName.length !== 0 &&
HTTP_TOKEN_CODEPOINTS.test(parameterName) &&
Expand All @@ -433,7 +433,7 @@ function forgivingBase64 (data) {
data = data.replace(ASCII_WHITESPACE_REPLACE_REGEX, '') // eslint-disable-line

let dataLength = data.length
// 2. If datas code point length divides by 4 leaving
// 2. If data's code point length divides by 4 leaving
// no remainder, then:
if (dataLength % 4 === 0) {
// 1. If data ends with one or two U+003D (=) code points,
Expand All @@ -446,7 +446,7 @@ function forgivingBase64 (data) {
}
}

// 3. If datas code point length divides by 4 leaving
// 3. If data's code point length divides by 4 leaving
// a remainder of 1, then return failure.
if (dataLength % 4 === 1) {
return 'failure'
Expand Down Expand Up @@ -551,11 +551,11 @@ function serializeAMimeType (mimeType) {
assert(mimeType !== 'failure')
const { parameters, essence } = mimeType

// 1. Let serialization be the concatenation of mimeTypes
// type, U+002F (/), and mimeTypes subtype.
// 1. Let serialization be the concatenation of mimeType's
// type, U+002F (/), and mimeType's subtype.
let serialization = essence

// 2. For each name → value of mimeTypes parameters:
// 2. For each name → value of mimeType's parameters:
for (let [name, value] of parameters.entries()) {
// 1. Append U+003B (;) to serialization.
serialization += ';'
Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function convertLineEndingsNative (s) {
// 1. Let native line ending be be the code point U+000A LF.
let nativeLineEnding = '\n'

// 2. If the underlying platforms conventions are to
// 2. If the underlying platform's conventions are to
// represent newlines as a carriage return and line feed
// sequence, set native line ending to the code point
// U+000D CR followed by the code point U+000A LF.
Expand Down
18 changes: 9 additions & 9 deletions lib/fetch/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FormData {
// name, value, and filename if given.
const entry = makeEntry(name, value, filename)

// 3. Append entry to thiss entry list.
// 3. Append entry to this's entry list.
this[kState].push(entry)
}

Expand All @@ -60,7 +60,7 @@ class FormData {
name = webidl.converters.USVString(name)

// The delete(name) method steps are to remove all entries whose name
// is name from thiss entry list.
// is name from this's entry list.
this[kState] = this[kState].filter(entry => entry.name !== name)
}

Expand All @@ -71,15 +71,15 @@ class FormData {

name = webidl.converters.USVString(name)

// 1. If there is no entry whose name is name in thiss entry list,
// 1. If there is no entry whose name is name in this's entry list,
// then return null.
const idx = this[kState].findIndex((entry) => entry.name === name)
if (idx === -1) {
return null
}

// 2. Return the value of the first entry whose name is name from
// thiss entry list.
// this's entry list.
return this[kState][idx].value
}

Expand All @@ -90,10 +90,10 @@ class FormData {

name = webidl.converters.USVString(name)

// 1. If there is no entry whose name is name in thiss entry list,
// 1. If there is no entry whose name is name in this's entry list,
// then return the empty list.
// 2. Return the values of all entries whose name is name, in order,
// from thiss entry list.
// from this's entry list.
return this[kState]
.filter((entry) => entry.name === name)
.map((entry) => entry.value)
Expand All @@ -107,7 +107,7 @@ class FormData {
name = webidl.converters.USVString(name)

// The has(name) method steps are to return true if there is an entry
// whose name is name in thiss entry list; otherwise false.
// whose name is name in this's entry list; otherwise false.
return this[kState].findIndex((entry) => entry.name === name) !== -1
}

Expand Down Expand Up @@ -139,7 +139,7 @@ class FormData {
// filename if given.
const entry = makeEntry(name, value, filename)

// 3. If there are entries in thiss entry list whose name is name, then
// 3. If there are entries in this's entry list whose name is name, then
// replace the first such entry with entry and remove the others.
const idx = this[kState].findIndex((entry) => entry.name === name)
if (idx !== -1) {
Expand All @@ -149,7 +149,7 @@ class FormData {
...this[kState].slice(idx + 1).filter((entry) => entry.name !== name)
]
} else {
// 4. Otherwise, append entry to thiss entry list.
// 4. Otherwise, append entry to this's entry list.
this[kState].push(entry)
}
}
Expand Down
Loading
Loading