Skip to content

Commit

Permalink
fix: use properly encodeURI and encodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Nov 1, 2016
1 parent 2f445e7 commit 1270364
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ export default class Path {
.map(t => t.val[0]);
}

_isSpatParam(name) {
return this.spatParams.indexOf(name) !== -1;
_isQueryParam(name) {
return this.queryParams.indexOf(name) !== -1 ||
this.queryParamsBr.indexOf(name) !== -1;
}

_urlTest(path, regex) {
Expand Down Expand Up @@ -243,7 +244,7 @@ export default class Path {
}

const val = params[key];
const encode = this._isSpatParam(key) ? encodeURI : encodeURIComponent;
const encode = this._isQueryParam(key) ? encodeURIComponent : encodeURI;

if (typeof val === 'boolean') {
acc[key] = val;
Expand Down
3 changes: 3 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,8 @@ describe('Path', function () {

path.partialTest('/test/he:re/test2').should.eql({ name: 'he:re' });
path.partialTest('/test/he\'re/test2').should.eql({ name: 'he\'re' });

path.build({ name: 'he:re' }).should.eql('/test/he:re/test2');
path.build({ name: 'he\'re' }).should.eql('/test/he\'re/test2');
});
});

0 comments on commit 1270364

Please sign in to comment.