Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove duplicated decodeURIComponent #3323

Merged
merged 4 commits into from Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/basic/app.js
Expand Up @@ -35,6 +35,7 @@ const Home = { template: '<div>home</div>' }
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Unicode = { template: '<div>unicode</div>' }
const Query = { template: '<div>query: {{ $route.params.q }}</div>' }

// 3. Create the router
const router = new VueRouter({
Expand All @@ -44,7 +45,8 @@ const router = new VueRouter({
{ path: '/', component: Home },
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{ path: '/é', component: Unicode }
{ path: '/é', component: Unicode },
{ path: '/query/:q', component: Query }
]
})

Expand Down Expand Up @@ -73,6 +75,7 @@ const vueInstance = new Vue({
</li>
</router-link>
<li><router-link to="/foo" replace>/foo (replace)</router-link></li>
<li><router-link to="/query/A%25">/query/A%</router-link></li>
</ul>
<button id="navigate-btn" @click="navigateAndIncrement">On Success</button>
<pre id="counter">{{ n }}</pre>
Expand Down
5 changes: 4 additions & 1 deletion examples/hash-mode/app.js
Expand Up @@ -35,6 +35,7 @@ const Home = { template: '<div>home</div>' }
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Unicode = { template: '<div>unicode: {{ $route.params.unicode }}</div>' }
const Query = { template: '<div>query: {{ $route.params.q }}</div>' }

// 3. Create the router
const router = new VueRouter({
Expand All @@ -45,7 +46,8 @@ const router = new VueRouter({
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{ path: '/é', component: Unicode },
{ path: '/é/:unicode', component: Unicode }
{ path: '/é/:unicode', component: Unicode },
{ path: '/query/:q', component: Query }
]
})

Expand All @@ -66,6 +68,7 @@ const vueInstance = new Vue({
<li><router-link to="/é/ñ">/é/ñ</router-link></li>
<li><router-link to="/é/ñ?t=%25ñ">/é/ñ?t=%ñ</router-link></li>
<li><router-link to="/é/ñ#é">/é/ñ#é</router-link></li>
<li><router-link to="/query/A%25">/query/A%</router-link></li>
</ul>
<pre id="query-t">{{ $route.query.t }}</pre>
<pre id="hash">{{ $route.hash }}</pre>
Expand Down
3 changes: 1 addition & 2 deletions src/create-matcher.js
Expand Up @@ -185,10 +185,9 @@ function matchRoute (

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

Expand Down
14 changes: 12 additions & 2 deletions test/e2e/specs/basic.js
Expand Up @@ -9,8 +9,8 @@ module.exports = {
browser
.url('http://localhost:8080/basic/')
.waitForElementVisible('#app', 1000)
.assert.count('li', 9)
.assert.count('li a', 9)
.assert.count('li', 10)
.assert.count('li a', 10)
// assert correct href with base
.assert.attributeContains('li:nth-child(1) a', 'href', '/basic/')
.assert.attributeContains('li:nth-child(2) a', 'href', '/basic/foo')
Expand All @@ -20,6 +20,7 @@ module.exports = {
.assert.attributeContains('li:nth-child(6) a', 'href', '/basic/%C3%A9?t=%25%C3%B1')
.assert.attributeContains('li:nth-child(7) a', 'href', '/basic/%C3%A9#%25%C3%B1')
.assert.attributeContains('li:nth-child(8) a', 'href', '/basic/foo')
.assert.attributeContains('li:nth-child(10) a', 'href', '/basic/query/A%25')
.assert.containsText('.view', 'home')

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

// encoded percentage as path param
// https://github.com/vuejs/vue-router/issues/2725
.url('http://localhost:8080/basic/query/A%25')
.waitForElementVisible('#app', 1000)
.assert.containsText('.view', 'query: A%')
posva marked this conversation as resolved.
Show resolved Hide resolved
.click('li:nth-child(10) a')
.assert.urlEquals('http://localhost:8080/basic/query/A%25')
.assert.containsText('.view', 'query: A%')
posva marked this conversation as resolved.
Show resolved Hide resolved

// Listener cleanup
.assert.containsText('#popstate-count', '1 popstate listeners')
.click('#unmount')
Expand Down
14 changes: 12 additions & 2 deletions test/e2e/specs/hash-mode.js
Expand Up @@ -9,14 +9,15 @@ module.exports = {
browser
.url('http://localhost:8080/hash-mode/')
.waitForElementVisible('#app', 1000)
.assert.count('li', 8)
.assert.count('li a', 7)
.assert.count('li', 9)
.assert.count('li a', 8)
.assert.attributeContains('li:nth-child(1) a', 'href', '/hash-mode/#/')
.assert.attributeContains('li:nth-child(2) a', 'href', '/hash-mode/#/foo')
.assert.attributeContains('li:nth-child(3) a', 'href', '/hash-mode/#/bar')
.assert.attributeContains('li:nth-child(5) a', 'href', '/hash-mode/#/%C3%A9')
.assert.attributeContains('li:nth-child(6) a', 'href', '/hash-mode/#/%C3%A9/%C3%B1')
.assert.attributeContains('li:nth-child(7) a', 'href', '/hash-mode/#/%C3%A9/%C3%B1?t=%25%C3%B1')
.assert.attributeContains('li:nth-child(9) a', 'href', '/hash-mode/#/query/A%25')
.assert.containsText('.view', 'home')

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

// percentage as path param
// https://github.com/vuejs/vue-router/issues/2725
.url('http://localhost:8080/hash-mode/#/query/A%25')
.waitForElementVisible('#app', 1000)
.assert.containsText('.view', 'query: A%')
.click('li:nth-child(9) a')
.assert.urlEquals('http://localhost:8080/hash-mode/#/query/A%25')
.assert.containsText('.view', 'query: A%')

// Listener cleanup
.assert.containsText('#popstate-count', '1 popstate listeners')
.click('#unmount')
Expand Down