From 80d3933d229e6f9058fccc37b2e37cb17ae7881c Mon Sep 17 00:00:00 2001 From: Alexey Khrushch Date: Sat, 15 Feb 2020 20:20:20 +0200 Subject: [PATCH 1/5] fix: set correct active route on init --- src/util/params.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/params.js b/src/util/params.js index 83d4aa11a..c48b7dcea 100644 --- a/src/util/params.js +++ b/src/util/params.js @@ -23,7 +23,7 @@ export function fillParams ( // and fix #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string if (typeof params.pathMatch === 'string') params[0] = params.pathMatch - return filler(params, { pretty: true }) + return decodeURI(filler(params, { pretty: true })) } catch (e) { if (process.env.NODE_ENV !== 'production') { // Fix #3072 no warn if `pathMatch` is string From d28fea695e5a2ccb2e48232dcbd577e3ba36ba26 Mon Sep 17 00:00:00 2001 From: Alexey Khrushch Date: Sat, 15 Feb 2020 20:28:46 +0200 Subject: [PATCH 2/5] chore(examples): add routes with special characters --- examples/route-matching/app.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/route-matching/app.js b/examples/route-matching/app.js index 2d0b6b6f1..cbf8679c9 100644 --- a/examples/route-matching/app.js +++ b/examples/route-matching/app.js @@ -21,7 +21,9 @@ const router = new VueRouter({ // asterisk can match anything { path: '/asterisk/*' }, // make part of the path optional by wrapping with parens and add "?" - { path: '/optional-group/(foo/)?bar' } + { path: '/optional-group/(foo/)?bar' }, + // processing routes with special characters + { path: '/special/:word', name: 'special' } ] }) @@ -41,6 +43,8 @@ new Vue({
  • /asterisk/foo/bar
  • /optional-group/bar
  • /optional-group/foo/bar
  • +
  • /special/tést1
  • +
  • /special/tést2
  • Route context

    {{ JSON.stringify($route, null, 2) }}
    From 20fa21f30df4cb13400f0eab70e60a70a0830da9 Mon Sep 17 00:00:00 2001 From: Alexey Khrushch Date: Sat, 15 Feb 2020 20:45:56 +0200 Subject: [PATCH 3/5] chore(test): coverage active router on init page --- test/e2e/specs/route-matching.js | 58 +++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index bd3646092..03a768804 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -9,7 +9,7 @@ module.exports = { browser .url('http://localhost:8080/route-matching/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 10) + .assert.count('li a', 12) .assert.evaluate( function () { var route = JSON.parse(document.querySelector('pre').textContent) @@ -176,6 +176,62 @@ module.exports = { null, '/optional-group/foo/bar' ) + + .click('li:nth-child(11) a') + .assert.evaluate( + function () { + var route = JSON.parse(document.querySelector('pre').textContent) + return ( + route.matched.length === 1 && + route.matched[0].path === '/special/:word' && + route.fullPath === '/special/tést1' && + JSON.stringify(route.params) === + JSON.stringify({ + word: 'tést1' + }) + ) + }, + null, + '/optional-group/special/tést1' + ) + + .click('li:nth-child(12) a') + .assert.evaluate( + function () { + var route = JSON.parse(document.querySelector('pre').textContent) + return ( + route.matched.length === 1 && + route.matched[0].path === '/special/:word' && + route.fullPath === '/special/tést2' && + JSON.stringify(route.params) === + JSON.stringify({ + word: 'tést2' + }) + ) + }, + null, + '/optional-group/special/tést2' + ) + + .url('http://localhost:8080/route-matching/special/tést1') + .waitForElementVisible('#app', 1000) + .assert.evaluate( + function () { + return document.querySelector('li:nth-child(11) a').classList.contains('router-link-active') + }, + null, + '/optional-group/special/tést1 init active router' + ) + + .url('http://localhost:8080/route-matching/special/tést2') + .waitForElementVisible('#app', 1000) + .assert.evaluate( + function () { + return document.querySelector('li:nth-child(12) a').classList.contains('router-link-active') + }, + null, + '/optional-group/special/tést2 init active router' + ) .end() } } From 62f16855e2e68d1c967a6e4d3d7fb97d88e8f24f Mon Sep 17 00:00:00 2001 From: Alexey Khrushch Date: Sun, 16 Feb 2020 21:28:23 +0200 Subject: [PATCH 4/5] chore: correct decode/encode fullpath --- examples/route-matching/app.js | 2 +- src/history/html5.js | 2 +- src/util/params.js | 2 +- test/e2e/specs/route-matching.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/route-matching/app.js b/examples/route-matching/app.js index cbf8679c9..3fb5b37f5 100644 --- a/examples/route-matching/app.js +++ b/examples/route-matching/app.js @@ -43,7 +43,7 @@ new Vue({
  • /asterisk/foo/bar
  • /optional-group/bar
  • /optional-group/foo/bar
  • -
  • /special/tést1
  • +
  • /special/tést1
  • /special/tést2
  • Route context

    diff --git a/src/history/html5.js b/src/history/html5.js index e1cdba97d..d0d16ebb0 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -76,5 +76,5 @@ export function getLocation (base: string): string { if (base && path.indexOf(base) === 0) { path = path.slice(base.length) } - return (path || '/') + window.location.search + window.location.hash + return encodeURI((path || '/')) + window.location.search + window.location.hash } diff --git a/src/util/params.js b/src/util/params.js index c48b7dcea..83d4aa11a 100644 --- a/src/util/params.js +++ b/src/util/params.js @@ -23,7 +23,7 @@ export function fillParams ( // and fix #3106 so that you can work with location descriptor object having params.pathMatch equal to empty string if (typeof params.pathMatch === 'string') params[0] = params.pathMatch - return decodeURI(filler(params, { pretty: true })) + return filler(params, { pretty: true }) } catch (e) { if (process.env.NODE_ENV !== 'production') { // Fix #3072 no warn if `pathMatch` is string diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index 03a768804..d6ff048e3 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -184,7 +184,7 @@ module.exports = { return ( route.matched.length === 1 && route.matched[0].path === '/special/:word' && - route.fullPath === '/special/tést1' && + route.fullPath === encodeURI('/special/tést1') && JSON.stringify(route.params) === JSON.stringify({ word: 'tést1' @@ -202,7 +202,7 @@ module.exports = { return ( route.matched.length === 1 && route.matched[0].path === '/special/:word' && - route.fullPath === '/special/tést2' && + route.fullPath === encodeURI('/special/tést2') && JSON.stringify(route.params) === JSON.stringify({ word: 'tést2' From 7085375ec1b6a1f579d839d633b2ddfc87d035f7 Mon Sep 17 00:00:00 2001 From: Alexey Khrushch Date: Tue, 26 May 2020 21:47:05 +0300 Subject: [PATCH 5/5] chore: code style --- test/e2e/specs/route-matching.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/e2e/specs/route-matching.js b/test/e2e/specs/route-matching.js index d6ff048e3..251f1c9e2 100644 --- a/test/e2e/specs/route-matching.js +++ b/test/e2e/specs/route-matching.js @@ -186,9 +186,9 @@ module.exports = { route.matched[0].path === '/special/:word' && route.fullPath === encodeURI('/special/tést1') && JSON.stringify(route.params) === - JSON.stringify({ - word: 'tést1' - }) + JSON.stringify({ + word: 'tést1' + }) ) }, null, @@ -204,9 +204,9 @@ module.exports = { route.matched[0].path === '/special/:word' && route.fullPath === encodeURI('/special/tést2') && JSON.stringify(route.params) === - JSON.stringify({ - word: 'tést2' - }) + JSON.stringify({ + word: 'tést2' + }) ) }, null,