Skip to content

Commit 90a545f

Browse files
committed
remove use of url.search
1 parent 1f587bc commit 90a545f

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

packages/plugin-network-instrumentation/lib/redact-query-parameters.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,40 @@ module.exports = function (url, redactedKeys) {
1616

1717
// Parse the URL - use a base only for relative URLs
1818
const urlObj = new URL(url, base)
19-
const params = urlObj.search ? new URLSearchParams(urlObj.search) : new URLSearchParams()
19+
20+
// Extract query string manually from the original URL
21+
const queryStart = url.indexOf('?')
22+
const hashStart = url.indexOf('#')
23+
24+
let queryString = ''
25+
if (queryStart !== -1) {
26+
const queryEnd = hashStart !== -1 && hashStart > queryStart ? hashStart : url.length
27+
queryString = url.substring(queryStart + 1, queryEnd)
28+
}
2029

2130
// Convert URLSearchParams to object without using Object.fromEntries()
31+
const params = new URLSearchParams(queryString)
2232
const paramsObject = {}
2333
params.forEach((value, key) => {
2434
paramsObject[key] = value
2535
})
2636

2737
const redactedParams = redactValues(paramsObject, redactedKeys)
28-
if (urlObj.search) {
29-
urlObj.search = new URLSearchParams(redactedParams).toString()
38+
const redactedQueryString = new URLSearchParams(redactedParams).toString()
39+
40+
// Build the result URL manually
41+
let result = urlObj.pathname
42+
if (redactedQueryString) {
43+
result += '?' + redactedQueryString
44+
}
45+
if (urlObj.hash) {
46+
result += urlObj.hash
3047
}
3148

3249
// Return appropriate format based on original URL type
3350
if (isAbsolute) {
34-
return decodeURI(urlObj.toString())
51+
return decodeURI(urlObj.origin + result)
3552
}
3653

37-
// For relative URLs, return only the path + search + hash components
38-
const relativePart = urlObj.pathname + (urlObj.search || '') + urlObj.hash
39-
return decodeURI(relativePart)
54+
return decodeURI(result)
4055
}

0 commit comments

Comments
 (0)