Skip to content

Commit b6b1858

Browse files
dragantlyyx990803
authored andcommitted
Fixed the query encoding order issue.
The original code would encode full path differently based on whether the path was supplied as `name` or as `path`. Fixed so that all branches conform to the same encoding order, which is encoding of URI components and then or URI itself. Also, route-recognizer would decode in inverse order (first decode URI components and then URI). That was fixed as well (encode and decode orders should be inverse).
1 parent d5c78be commit b6b1858

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/route-recognizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,15 @@ RouteRecognizer.prototype = {
490490
pathLen, i, l, queryStart, queryParams = {},
491491
isSlashDropped = false;
492492

493+
path = decodeURI(path);
494+
493495
queryStart = path.indexOf('?');
494496
if (queryStart !== -1) {
495497
var queryString = path.substr(queryStart + 1, path.length);
496498
path = path.substr(0, queryStart);
497499
queryParams = this.parseQueryString(queryString);
498500
}
499501

500-
path = decodeURI(path);
501-
502502
// DEBUG GROUP path
503503

504504
if (path.charAt(0) !== "/") { path = "/" + path; }

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class Router {
320320
}
321321
fullPath = encodeURI(this._recognizer.generate(path.name, params))
322322
} else if (path.path) {
323-
fullPath = encodeURI(path.path)
323+
fullPath = path.path
324324
if (path.query) {
325325
const query = this._recognizer.generateQueryString(path.query)
326326
if (fullPath.indexOf('?') > -1) {
@@ -329,6 +329,7 @@ class Router {
329329
fullPath += query
330330
}
331331
}
332+
fullPath = encodeURI(fullPath)
332333
}
333334
} else {
334335
fullPath = encodeURI(path ? path + '' : '')

0 commit comments

Comments
 (0)