diff --git a/common/rule-processor/tests/processors/QueryParamsRuleProcessor.spec.js b/common/rule-processor/tests/processors/QueryParamsRuleProcessor.spec.js index 0b09a4e0d5..28a8ef0205 100644 --- a/common/rule-processor/tests/processors/QueryParamsRuleProcessor.spec.js +++ b/common/rule-processor/tests/processors/QueryParamsRuleProcessor.spec.js @@ -64,6 +64,26 @@ describe("QueryParamsRuleProcessor:", function () { ).toBe(URL_SOURCES.EXAMPLE + "?b=2"); }); + it("should preserve equals signs in existing query param values", function () { + const addModification = { + type: CONSTANTS.MODIFICATION_TYPES.ADD, + param: "added", + value: "2", + }; + const removeModification = { + type: CONSTANTS.MODIFICATION_TYPES.REMOVE, + param: "remove", + }; + const url = URL_SOURCES.EXAMPLE + "?token=abc==&remove=1"; + + expect(QueryParamsRuleProcessor.applyQueryParamModifications([addModification], url)).toBe( + URL_SOURCES.EXAMPLE + "?token=abc==&remove=1&added=2" + ); + expect(QueryParamsRuleProcessor.applyQueryParamModifications([removeModification], url)).toBe( + URL_SOURCES.EXAMPLE + "?token=abc==" + ); + }); + it("add and remove param should not create any effect", function () { var modifications = queryParamsRule.pairs[0]["modifications"]; diff --git a/common/utils.js b/common/utils.js index 02969d2587..f7cca0a385 100644 --- a/common/utils.js +++ b/common/utils.js @@ -159,8 +159,9 @@ export function getQueryParamsMap(queryString) { queryParams = queryString.split("&"); queryParams.forEach(function (queryParam) { - var paramName = queryParam.split("=")[0], - paramValue = queryParam.split("=")[1]; + var separatorIndex = queryParam.indexOf("="), + paramName = separatorIndex === -1 ? queryParam : queryParam.slice(0, separatorIndex), + paramValue = separatorIndex === -1 ? undefined : queryParam.slice(separatorIndex + 1); // We are keeping value of param as array so that in future we can support multiple param values of same name // And we do not want to lose the params if url already contains multiple params of same name