Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: rename buildUrl to serializePathWithQuery
  • Loading branch information
Uzlopak committed Sep 4, 2024
commit aab55cd543fd149c9c4479eb77bdbc7959cd8af3
4 changes: 2 additions & 2 deletions lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
isFormDataLike,
isIterable,
isBlobLike,
buildURL,
serializePathWithQuery,
validateHandler,
getServerName,
normalizedMethodRecords
Expand Down Expand Up @@ -135,7 +135,7 @@ class Request {

this.upgrade = upgrade || null

this.path = query ? buildURL(path, query) : path
this.path = query ? serializePathWithQuery(path, query) : path

this.origin = origin

Expand Down
9 changes: 7 additions & 2 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ function isBlobLike (object) {
}
}

function buildURL (url, queryParams) {
/**
* @param {string} url The URL to add the query params to
* @param {import('node:querystring').ParsedUrlQueryInput} queryParams The object to serialize into a URL query string
* @returns {string} The URL with the query params added
*/
function serializePathWithQuery (url, queryParams) {
if (url.includes('?') || url.includes('#')) {
throw new Error('Query params cannot be passed when url already contains "?" or "#".')
}
Expand Down Expand Up @@ -692,7 +697,7 @@ module.exports = {
validateHandler,
getSocketInfo,
isFormDataLike,
buildURL,
serializePathWithQuery,
addAbortListener,
isValidHTTPToken,
isValidHeaderValue,
Expand Down
4 changes: 2 additions & 2 deletions lib/mock/mock-interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
kMockDispatch
} = require('./mock-symbols')
const { InvalidArgumentError } = require('../core/errors')
const { buildURL } = require('../core/util')
const { serializePathWithQuery } = require('../core/util')

/**
* Defines the scope API for an interceptor reply
Expand Down Expand Up @@ -72,7 +72,7 @@ class MockInterceptor {
// fragments to servers when they retrieve a document,
if (typeof opts.path === 'string') {
if (opts.query) {
opts.path = buildURL(opts.path, opts.query)
opts.path = serializePathWithQuery(opts.path, opts.query)
} else {
// Matches https://github.com/nodejs/undici/blob/main/lib/web/fetch/index.js#L1811
const parsedURL = new URL(opts.path, 'data://')
Expand Down
4 changes: 2 additions & 2 deletions lib/mock/mock-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
kOrigin,
kGetNetConnect
} = require('./mock-symbols')
const { buildURL } = require('../core/util')
const { serializePathWithQuery } = require('../core/util')
const { STATUS_CODES } = require('node:http')
const {
types: {
Expand Down Expand Up @@ -126,7 +126,7 @@ function getResponseData (data) {
}

function getMockDispatch (mockDispatches, key) {
const basePath = key.query ? buildURL(key.path, key.query) : key.path
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path
const resolvedPath = typeof basePath === 'string' ? safeUrl(basePath) : basePath

// Match path
Expand Down