Commit d797b03b authored by Clement Ho's avatar Clement Ho

Fix bug where spaces would conver into + for all values

parent 3ce7f23a
...@@ -62,7 +62,11 @@ ...@@ -62,7 +62,11 @@
params.forEach((p) => { params.forEach((p) => {
const split = p.split('='); const split = p.split('=');
const key = decodeURIComponent(split[0]); const key = decodeURIComponent(split[0]);
const value = decodeURIComponent(split[1]); const value = split[1];
// Sanitize value since URL converts spaces into +
// Replace before decode so that we know what was originally + versus the encoded +
const sanitizedValue = value ? decodeURIComponent(value.replace(/[+]/g, ' ')) : value;
const match = validTokenKeys.find((t) => { const match = validTokenKeys.find((t) => {
return key === `${t.key}_${t.param}`; return key === `${t.key}_${t.param}`;
...@@ -70,22 +74,20 @@ ...@@ -70,22 +74,20 @@
if (match) { if (match) {
const sanitizedKey = key.slice(0, key.indexOf('_')); const sanitizedKey = key.slice(0, key.indexOf('_'));
const valueHasSpace = value.indexOf(' ') !== -1; const valueHasSpace = sanitizedValue.indexOf(' ') !== -1;
const preferredQuotations = '"'; const preferredQuotations = '"';
let quotationsToUse = preferredQuotations; let quotationsToUse = preferredQuotations;
if (valueHasSpace) { if (valueHasSpace) {
// Prefer ", but use ' if required // Prefer ", but use ' if required
quotationsToUse = value.indexOf(preferredQuotations) === -1 ? preferredQuotations : '\''; quotationsToUse = sanitizedValue.indexOf(preferredQuotations) === -1 ? preferredQuotations : '\'';
} }
inputValue += valueHasSpace ? `${sanitizedKey}:${quotationsToUse}${value}${quotationsToUse}` : `${sanitizedKey}:${value}`; inputValue += valueHasSpace ? `${sanitizedKey}:${quotationsToUse}${sanitizedValue}${quotationsToUse}` : `${sanitizedKey}:${sanitizedValue}`;
inputValue += ' '; inputValue += ' ';
} else if (!match && key === 'search') { } else if (!match && key === 'search') {
// Sanitize value as URL converts spaces into +
const sanitizedValue = value.replace(/[+]/g, ' ');
inputValue += sanitizedValue; inputValue += sanitizedValue;
inputValue += ' '; inputValue += ' ';
} }
...@@ -213,7 +215,7 @@ ...@@ -213,7 +215,7 @@
}); });
if (this.searchToken) { if (this.searchToken) {
path += '&search=' + encodeURIComponent(this.searchToken.replace(/ /g, '+')); path += '&search=' + encodeURIComponent(this.searchToken);
} }
window.location = path; window.location = path;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment