Skip to content

Commit

Permalink
Use + instead of %20 for spaces in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jun 27, 2015
1 parent 0b78745 commit d955d7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions modules/URLUtils.js
Expand Up @@ -117,7 +117,7 @@ export function matchPattern(pattern, pathname) {
var remainingPathname, paramValues;
if (match != null) {
paramValues = Array.prototype.slice.call(match, 1).map(function (v) {
return v != null ? decodeURIComponent(v) : v;
return v != null ? decodeURIComponent(v.replace(/\+/g, '%20')) : v;
});

if (captureRemaining) {
Expand Down Expand Up @@ -177,7 +177,7 @@ export function formatPattern(pattern, params) {
);

if (paramValue != null)
pathname += encodeURI(paramValue);
pathname += encodeURI(paramValue).replace(/%20/g, '+');
} else if (token === '(') {
parenCount += 1;
} else if (token === ')') {
Expand All @@ -193,7 +193,7 @@ export function formatPattern(pattern, params) {
);

if (paramValue != null)
pathname += encodeURIComponent(paramValue);
pathname += encodeURIComponent(paramValue).replace(/%20/g, '+');
} else {
pathname += token;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/__tests__/URLUtils-test.js
Expand Up @@ -245,7 +245,7 @@ describe('formatPattern', function () {

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

Expand Down

0 comments on commit d955d7a

Please sign in to comment.