From 607ce2d635dbbf2cfc4553357571310225114575 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 6 Oct 2020 11:43:16 +0200 Subject: [PATCH] fix(encoding): try catch decodes --- examples/hash-mode/app.js | 8 +++++--- src/create-matcher.js | 9 ++++++++- src/util/query.js | 11 ++++++++++- test/e2e/runner.js | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/examples/hash-mode/app.js b/examples/hash-mode/app.js index 9da4f5cb1..ee58238e9 100644 --- a/examples/hash-mode/app.js +++ b/examples/hash-mode/app.js @@ -47,7 +47,7 @@ const router = new VueRouter({ { path: '/bar', component: Bar }, { path: '/é', component: Unicode }, { path: '/é/:unicode', component: Unicode }, - { path: '/query/:q', component: Query } + { path: '/query/:q', component: Query, name: 'param' } ] }) @@ -69,14 +69,16 @@ const vueInstance = new Vue({
  • /é/ñ?t=%ñ
  • /é/ñ#é
  • /query/A%
  • +
  • /query/A% (object)
  • +
  • /query/A%2FE
  • +
  • /query/A%2FE (object)
  • {{ $route.query.t }}
    {{ $route.hash }}
    `, - methods: { - } + methods: {} }).$mount('#app') document.getElementById('unmount').addEventListener('click', () => { diff --git a/src/create-matcher.js b/src/create-matcher.js index c67538bc8..bb2235094 100644 --- a/src/create-matcher.js +++ b/src/create-matcher.js @@ -175,7 +175,14 @@ function matchRoute ( path: string, params: Object ): boolean { - const m = decodeURI(path).match(regex) + let m + try { + m = decodeURI(path).match(regex) + } catch (err) { + if (process.env.NODE_ENV !== 'production') { + warn(`Error decoding "${path}". Leaving it intact.`) + } + } if (!m) { return false diff --git a/src/util/query.js b/src/util/query.js index fef509a44..debcd26c5 100644 --- a/src/util/query.js +++ b/src/util/query.js @@ -14,7 +14,16 @@ const encode = str => .replace(encodeReserveRE, encodeReserveReplacer) .replace(commaRE, ',') -const decode = decodeURIComponent +export function decode (str) { + try { + return decodeURIComponent(str) + } catch (err) { + if (process.env.NODE_ENV !== 'production') { + warn(`Error decoding "${str}". Leaving it intact.`) + } + } + return str +} export function resolveQuery ( query: ?string, diff --git a/test/e2e/runner.js b/test/e2e/runner.js index 1608e94e9..8f552be51 100644 --- a/test/e2e/runner.js +++ b/test/e2e/runner.js @@ -61,7 +61,7 @@ if (args.indexOf('-c') < 0) { function adaptArgv (argv) { // take every remaining argument and treat it as a test file // this allows to run `node test/e2e/runner.js test/e2e/basic.js` - argv.retries = 1 + argv.retries = process.env.CI ? 1 : 0 argv.test = argv['_'].slice(0) if (argv.c === DEFAULT_CONFIG && argv.config === DEFAULT_CONFIG) {