Commit 4fdc34c1 authored by Paul Slaughter's avatar Paul Slaughter

Fix mergeUrlParams handling of `+`

**What was the issue?**
If a param value had `+`, it would be encoded as a
literal `+` instead of a space.
parent b1905a39
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('='));
}
});
}
......
---
title: Fix search preserving space when change branch
merge_request: 31973
author: minghuan lei
type: fixed
......@@ -94,6 +94,12 @@ describe('URL utility', () => {
it('adds and updates encoded params', () => {
expect(urlUtils.mergeUrlParams({ a: '&', q: '?' }, '?a=%23#frag')).toBe('?a=%26&q=%3F#frag');
});
it('treats "+" as "%20"', () => {
expect(urlUtils.mergeUrlParams({ ref: 'bogus' }, '?a=lorem+ipsum&ref=charlie')).toBe(
'?a=lorem%20ipsum&ref=bogus',
);
});
});
describe('removeParams', () => {
......
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