Skip to content

Commit

Permalink
fix(encoding): try catch decodes
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Oct 6, 2020
1 parent c3e613c commit 607ce2d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
8 changes: 5 additions & 3 deletions examples/hash-mode/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
]
})

Expand All @@ -69,14 +69,16 @@ const vueInstance = new Vue({
<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>
<li><router-link :to="{ name: 'param', params: { q: 'A%' }}">/query/A% (object)</router-link></li>
<li><router-link to="/query/A%2FE">/query/A%2FE</router-link></li>
<li><router-link :to="{ name: 'param', params: { q: 'A/E' }}">/query/A%2FE (object)</router-link></li>
</ul>
<pre id="query-t">{{ $route.query.t }}</pre>
<pre id="hash">{{ $route.hash }}</pre>
<router-view class="view"></router-view>
</div>
`,
methods: {
}
methods: {}
}).$mount('#app')

document.getElementById('unmount').addEventListener('click', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/create-matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/util/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 607ce2d

Please sign in to comment.