Skip to content

Commit 2730df8

Browse files
fix(vuejs#2725): remove duplicated decodeURIComponent
1 parent b8a6d60 commit 2730df8

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

examples/basic/app.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const Home = { template: '<div>home</div>' }
3535
const Foo = { template: '<div>foo</div>' }
3636
const Bar = { template: '<div>bar</div>' }
3737
const Unicode = { template: '<div>unicode</div>' }
38+
const Query = { template: '<div>query: {{ $route.params.q }}</div>' }
3839

3940
// 3. Create the router
4041
const router = new VueRouter({
@@ -44,7 +45,8 @@ const router = new VueRouter({
4445
{ path: '/', component: Home },
4546
{ path: '/foo', component: Foo },
4647
{ path: '/bar', component: Bar },
47-
{ path: '/é', component: Unicode }
48+
{ path: '/é', component: Unicode },
49+
{ path: '/query/:q', component: Query }
4850
]
4951
})
5052

@@ -73,6 +75,7 @@ const vueInstance = new Vue({
7375
</li>
7476
</router-link>
7577
<li><router-link to="/foo" replace>/foo (replace)</router-link></li>
78+
<li><router-link to="/query/A%25">/query/A%</router-link></li>
7679
</ul>
7780
<button id="navigate-btn" @click="navigateAndIncrement">On Success</button>
7881
<pre id="counter">{{ n }}</pre>

examples/hash-mode/app.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const Home = { template: '<div>home</div>' }
3535
const Foo = { template: '<div>foo</div>' }
3636
const Bar = { template: '<div>bar</div>' }
3737
const Unicode = { template: '<div>unicode: {{ $route.params.unicode }}</div>' }
38+
const Query = { template: '<div>query: {{ $route.params.q }}</div>' }
3839

3940
// 3. Create the router
4041
const router = new VueRouter({
@@ -45,7 +46,8 @@ const router = new VueRouter({
4546
{ path: '/foo', component: Foo },
4647
{ path: '/bar', component: Bar },
4748
{ path: '/é', component: Unicode },
48-
{ path: '/é/:unicode', component: Unicode }
49+
{ path: '/é/:unicode', component: Unicode },
50+
{ path: '/query/:q', component: Query }
4951
]
5052
})
5153

@@ -66,6 +68,7 @@ const vueInstance = new Vue({
6668
<li><router-link to="/é/ñ">/é/ñ</router-link></li>
6769
<li><router-link to="/é/ñ?t=%25ñ">/é/ñ?t=%ñ</router-link></li>
6870
<li><router-link to="/é/ñ#é">/é/ñ#é</router-link></li>
71+
<li><router-link to="/query/A%25">/query/A%</router-link></li>
6972
</ul>
7073
<pre id="query-t">{{ $route.query.t }}</pre>
7174
<pre id="hash">{{ $route.hash }}</pre>

src/create-matcher.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,9 @@ function matchRoute (
185185

186186
for (let i = 1, len = m.length; i < len; ++i) {
187187
const key = regex.keys[i - 1]
188-
const val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]
189188
if (key) {
190189
// Fix #1994: using * with props: true generates a param named 0
191-
params[key.name || 'pathMatch'] = val
190+
params[key.name || 'pathMatch'] = m[i]
192191
}
193192
}
194193

test/e2e/specs/basic.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = {
99
browser
1010
.url('http://localhost:8080/basic/')
1111
.waitForElementVisible('#app', 1000)
12-
.assert.count('li', 9)
13-
.assert.count('li a', 9)
12+
.assert.count('li', 10)
13+
.assert.count('li a', 10)
1414
// assert correct href with base
1515
.assert.attributeContains('li:nth-child(1) a', 'href', '/basic/')
1616
.assert.attributeContains('li:nth-child(2) a', 'href', '/basic/foo')
@@ -20,6 +20,7 @@ module.exports = {
2020
.assert.attributeContains('li:nth-child(6) a', 'href', '/basic/%C3%A9?t=%25%C3%B1')
2121
.assert.attributeContains('li:nth-child(7) a', 'href', '/basic/%C3%A9#%25%C3%B1')
2222
.assert.attributeContains('li:nth-child(8) a', 'href', '/basic/foo')
23+
.assert.attributeContains('li:nth-child(10) a', 'href', '/basic/query/A%25')
2324
.assert.containsText('.view', 'home')
2425

2526
.click('li:nth-child(2) a')
@@ -70,6 +71,15 @@ module.exports = {
7071
.assert.cssClassPresent('li:nth-child(8)', 'exact-active')
7172
.assert.attributeEquals('li:nth-child(8) a', 'class', '')
7273

74+
// encoded percentage as path param
75+
// https://github.com/vuejs/vue-router/issues/2725
76+
.url('http://localhost:8080/basic/query/A%25')
77+
.waitForElementVisible('#app', 1000)
78+
.assert.containsText('.view', 'query: A%')
79+
.click('li:nth-child(10) a')
80+
.assert.urlEquals('http://localhost:8080/basic/query/A%25')
81+
.assert.containsText('.view', 'query: A%')
82+
7383
// Listener cleanup
7484
.assert.containsText('#popstate-count', '1 popstate listeners')
7585
.click('#unmount')

test/e2e/specs/hash-mode.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ module.exports = {
99
browser
1010
.url('http://localhost:8080/hash-mode/')
1111
.waitForElementVisible('#app', 1000)
12-
.assert.count('li', 8)
13-
.assert.count('li a', 7)
12+
.assert.count('li', 9)
13+
.assert.count('li a', 8)
1414
.assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/')
1515
.assert.attributeContains('li:nth-child(2) a', 'href', '/hash-mode/#/foo')
1616
.assert.attributeContains('li:nth-child(3) a', 'href', '/hash-mode/#/bar')
1717
.assert.attributeContains('li:nth-child(5) a', 'href', '/hash-mode/#/%C3%A9')
1818
.assert.attributeContains('li:nth-child(6) a', 'href', '/hash-mode/#/%C3%A9/%C3%B1')
1919
.assert.attributeContains('li:nth-child(7) a', 'href', '/hash-mode/#/%C3%A9/%C3%B1?t=%25%C3%B1')
20+
.assert.attributeContains('li:nth-child(9) a', 'href', '/hash-mode/#/query/A%25')
2021
.assert.containsText('.view', 'home')
2122

2223
.click('li:nth-child(2) a')
@@ -58,6 +59,15 @@ module.exports = {
5859
.assert.containsText('.view', 'unicode: ñ')
5960
.assert.containsText('#query-t', '%')
6061

62+
// percentage as path param
63+
// https://github.com/vuejs/vue-router/issues/2725
64+
.url('http://localhost:8080/hash-mode/#/query/A%25')
65+
.waitForElementVisible('#app', 1000)
66+
.assert.containsText('.view', 'query: A%')
67+
.click('li:nth-child(9) a')
68+
.assert.urlEquals('http://localhost:8080/hash-mode/#/query/A%25')
69+
.assert.containsText('.view', 'query: A%')
70+
6171
// Listener cleanup
6272
.assert.containsText('#popstate-count', '1 popstate listeners')
6373
.click('#unmount')

0 commit comments

Comments
 (0)