Bug 1962993 - [devtools] Use URLSearchParams to build URL in HTTPCustomRequestPanel#onUpdateQueryParams. r=devtools-reviewers,bomsy

Differential Revision: https://phabricator.services.mozilla.com/D246893
This commit is contained in:
Nicolas Chevobbe
2025-04-29 11:38:20 +00:00
parent 7918e3ccd4
commit 19d80d6778
3 changed files with 9 additions and 11 deletions

View File

@@ -22,6 +22,7 @@ const {
getClickedRequest, getClickedRequest,
} = require("resource://devtools/client/netmonitor/src/selectors/index.js"); } = require("resource://devtools/client/netmonitor/src/selectors/index.js");
const { const {
getUrl,
getUrlQuery, getUrlQuery,
parseQueryString, parseQueryString,
} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); } = require("resource://devtools/client/netmonitor/src/utils/request-utils.js");
@@ -269,22 +270,18 @@ class HTTPCustomRequestPanel extends Component {
onUpdateQueryParams() { onUpdateQueryParams() {
const { urlQueryParams, url } = this.state; const { urlQueryParams, url } = this.state;
let queryString = "";
const urlObj = getUrl(url);
urlObj.search = "";
for (const { name, value, checked } of urlQueryParams) { for (const { name, value, checked } of urlQueryParams) {
if (checked) { if (checked) {
queryString += `${encodeURIComponent(name)}=${encodeURIComponent( urlObj.searchParams.set(name, value);
value
)}&`;
} }
} }
let finalURL = url.split("?")[0];
if (queryString.length) {
finalURL += `?${queryString.substring(0, queryString.length - 1)}`;
}
this.setState({ this.setState({
url: finalURL, url: urlObj.toString(),
}); });
} }

View File

@@ -820,6 +820,7 @@ module.exports = {
getResponseHeader, getResponseHeader,
getResponseTime, getResponseTime,
getStartTime, getStartTime,
getUrl,
getUrlBaseName, getUrlBaseName,
getUrlDetails, getUrlDetails,
getUrlHost, getUrlHost,

View File

@@ -138,7 +138,7 @@ async function runTests(tab, monitor, document, isPrivate = false) {
is( is(
customUrl.value, customUrl.value,
"https://www.example.com?My-param=", "https://www.example.com/?My-param=",
"The url should still be there after the user close the panel and re-opened" "The url should still be there after the user close the panel and re-opened"
); );