From 4fdc34c10950863ad04a68dc2117371c95db7478 Mon Sep 17 00:00:00 2001 From: Paul Slaughter Date: Mon, 19 Aug 2019 09:00:10 -0500 Subject: Fix mergeUrlParams handling of `+` **What was the issue?** If a param value had `+`, it would be encoded as a literal `+` instead of a space. --- app/assets/javascripts/lib/utils/url_utility.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/assets/javascripts/lib/utils/url_utility.js') diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js index 1336b6a5461..7ead9d46fbb 100644 --- a/app/assets/javascripts/lib/utils/url_utility.js +++ b/app/assets/javascripts/lib/utils/url_utility.js @@ -1,5 +1,11 @@ import { join as joinPaths } from 'path'; +// Returns a decoded url parameter value +// - Treats '+' as '%20' +function decodeUrlParameter(val) { + return decodeURIComponent(val.replace(/\+/g, '%20')); +} + // Returns an array containing the value(s) of the // of the key passed as an argument export function getParameterValues(sParam, url = window.location) { @@ -30,7 +36,7 @@ export function mergeUrlParams(params, url) { .forEach(part => { if (part.length) { const kv = part.split('='); - merged[decodeURIComponent(kv[0])] = decodeURIComponent(kv.slice(1).join('=')); + merged[decodeUrlParameter(kv[0])] = decodeUrlParameter(kv.slice(1).join('=')); } }); } -- cgit v1.2.3