Skip to content

Commit d955d7a

Browse files
committed
Use + instead of %20 for spaces in URLs
1 parent 0b78745 commit d955d7a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

modules/URLUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function matchPattern(pattern, pathname) {
117117
var remainingPathname, paramValues;
118118
if (match != null) {
119119
paramValues = Array.prototype.slice.call(match, 1).map(function (v) {
120-
return v != null ? decodeURIComponent(v) : v;
120+
return v != null ? decodeURIComponent(v.replace(/\+/g, '%20')) : v;
121121
});
122122

123123
if (captureRemaining) {
@@ -177,7 +177,7 @@ export function formatPattern(pattern, params) {
177177
);
178178

179179
if (paramValue != null)
180-
pathname += encodeURI(paramValue);
180+
pathname += encodeURI(paramValue).replace(/%20/g, '+');
181181
} else if (token === '(') {
182182
parenCount += 1;
183183
} else if (token === ')') {
@@ -193,7 +193,7 @@ export function formatPattern(pattern, params) {
193193
);
194194

195195
if (paramValue != null)
196-
pathname += encodeURIComponent(paramValue);
196+
pathname += encodeURIComponent(paramValue).replace(/%20/g, '+');
197197
} else {
198198
pathname += token;
199199
}

modules/__tests__/URLUtils-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ describe('formatPattern', function () {
245245

246246
describe('and some params have special URL encoding', function () {
247247
it('returns the correct path', function () {
248-
expect(formatPattern(pattern, { id: 'one, two' })).toEqual('comments/one%2C%20two/edit');
248+
expect(formatPattern(pattern, { id: 'one, two' })).toEqual('comments/one%2C+two/edit');
249249
});
250250
});
251251

0 commit comments

Comments
 (0)