Skip to content

Commit 89a46dd

Browse files
authored
chore: rename buildUrl to serializePathWithQuery + jsdoc (#3545)
* chore: rename buildUrl to serializePathWithQuery * fix
1 parent 030ce23 commit 89a46dd

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

lib/core/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
isFormDataLike,
1515
isIterable,
1616
isBlobLike,
17-
buildURL,
17+
serializePathWithQuery,
1818
validateHandler,
1919
getServerName,
2020
normalizedMethodRecords
@@ -135,7 +135,7 @@ class Request {
135135

136136
this.upgrade = upgrade || null
137137

138-
this.path = query ? buildURL(path, query) : path
138+
this.path = query ? serializePathWithQuery(path, query) : path
139139

140140
this.origin = origin
141141

lib/core/util.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ function isBlobLike (object) {
8989
}
9090
}
9191

92-
function buildURL (url, queryParams) {
92+
/**
93+
* @param {string} url The URL to add the query params to
94+
* @param {import('node:querystring').ParsedUrlQueryInput} queryParams The object to serialize into a URL query string
95+
* @returns {string} The URL with the query params added
96+
*/
97+
function serializePathWithQuery (url, queryParams) {
9398
if (url.includes('?') || url.includes('#')) {
9499
throw new Error('Query params cannot be passed when url already contains "?" or "#".')
95100
}
@@ -689,7 +694,7 @@ module.exports = {
689694
validateHandler,
690695
getSocketInfo,
691696
isFormDataLike,
692-
buildURL,
697+
serializePathWithQuery,
693698
addAbortListener,
694699
isValidHTTPToken,
695700
isValidHeaderValue,

lib/mock/mock-interceptor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
kMockDispatch
1111
} = require('./mock-symbols')
1212
const { InvalidArgumentError } = require('../core/errors')
13-
const { buildURL } = require('../core/util')
13+
const { serializePathWithQuery } = require('../core/util')
1414

1515
/**
1616
* Defines the scope API for an interceptor reply
@@ -72,7 +72,7 @@ class MockInterceptor {
7272
// fragments to servers when they retrieve a document,
7373
if (typeof opts.path === 'string') {
7474
if (opts.query) {
75-
opts.path = buildURL(opts.path, opts.query)
75+
opts.path = serializePathWithQuery(opts.path, opts.query)
7676
} else {
7777
// Matches https://github.com/nodejs/undici/blob/main/lib/web/fetch/index.js#L1811
7878
const parsedURL = new URL(opts.path, 'data://')

lib/mock/mock-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {
88
kOrigin,
99
kGetNetConnect
1010
} = require('./mock-symbols')
11-
const { buildURL } = require('../core/util')
11+
const { serializePathWithQuery } = require('../core/util')
1212
const { STATUS_CODES } = require('node:http')
1313
const {
1414
types: {
@@ -126,7 +126,7 @@ function getResponseData (data) {
126126
}
127127

128128
function getMockDispatch (mockDispatches, key) {
129-
const basePath = key.query ? buildURL(key.path, key.query) : key.path
129+
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path
130130
const resolvedPath = typeof basePath === 'string' ? safeUrl(basePath) : basePath
131131

132132
// Match path

test/node-test/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test('parseRawHeaders', () => {
9292
assert.deepEqual(util.parseRawHeaders(['content-length', 'value', 'content-disposition', 'form-data; name="fieldName"']), ['content-length', 'value', 'content-disposition', 'form-data; name="fieldName"'])
9393
})
9494

95-
test('buildURL', () => {
95+
test('serializePathWithQuery', () => {
9696
const tests = [
9797
[{ id: BigInt(123456) }, 'id=123456'],
9898
[{ date: new Date() }, 'date='],
@@ -111,7 +111,7 @@ test('buildURL', () => {
111111

112112
for (const [input, output] of tests) {
113113
const expected = `${base}${output ? `?${output}` : output}`
114-
assert.deepEqual(util.buildURL(base, input), expected)
114+
assert.deepEqual(util.serializePathWithQuery(base, input), expected)
115115
}
116116
})
117117

0 commit comments

Comments
 (0)