Skip to content

Commit bd0ee3f

Browse files
authored
Revert the router's path string decoding strategy (fixes #3064) (#3065)
1 parent c50e6be commit bd0ee3f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

api/router.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ module.exports = function($window, mountRedraw) {
5252
if (prefix[0] !== "/") prefix = "/" + prefix
5353
}
5454
}
55-
var path = decodeURIComponentSafe(prefix).slice(route.prefix.length)
55+
// This seemingly useless `.concat()` speeds up the tests quite a bit,
56+
// since the representation is consistently a relatively poorly
57+
// optimized cons string.
58+
var path = prefix.concat()
59+
.replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponentSafe)
60+
.slice(route.prefix.length)
5661
var data = parsePathname(path)
5762

5863
Object.assign(data.params, $window.history.state)

api/tests/test-routerGetSet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ o.spec("route.get/route.set", function() {
220220
route.set("/other/:a/:b", {a: "x", b: "y/z", c: "d", e: "f"})
221221
setTimeout(function() {
222222
// Yep, before even the throttle mechanism takes hold.
223-
o(route.get()).equals("/other/x/y/z?c=d&e=f")
223+
o(route.get()).equals("/other/x/y%2Fz?c=d&e=f")
224224
throttleMock.fire()
225225
done()
226226
})

pathname/compileTemplate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict"
22

33
var parsePathname = require("./parse")
4+
var decodeURIComponentSafe = require("../util/decodeURIComponentSafe")
45

56
// Compiles a template into a function that takes a resolved path (without query
67
// strings) and returns an object containing the template parameters with their
@@ -36,7 +37,7 @@ module.exports = function(template) {
3637
var values = regexp.exec(data.path)
3738
if (values == null) return false
3839
for (var i = 0; i < keys.length; i++) {
39-
data.params[keys[i].k] = keys[i].r ? values[i + 1] : decodeURIComponent(values[i + 1])
40+
data.params[keys[i].k] = keys[i].r ? values[i + 1] : decodeURIComponentSafe(values[i + 1])
4041
}
4142
return true
4243
}

0 commit comments

Comments
 (0)