Skip to content

Commit 607ce2d

Browse files
committedOct 6, 2020
fix(encoding): try catch decodes
1 parent c3e613c commit 607ce2d

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed
 

‎examples/hash-mode/app.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const router = new VueRouter({
4747
{ path: '/bar', component: Bar },
4848
{ path: '/é', component: Unicode },
4949
{ path: '/é/:unicode', component: Unicode },
50-
{ path: '/query/:q', component: Query }
50+
{ path: '/query/:q', component: Query, name: 'param' }
5151
]
5252
})
5353

@@ -69,14 +69,16 @@ const vueInstance = new Vue({
6969
<li><router-link to="/é/ñ?t=%25ñ">/é/ñ?t=%ñ</router-link></li>
7070
<li><router-link to="/é/ñ#é">/é/ñ#é</router-link></li>
7171
<li><router-link to="/query/A%25">/query/A%</router-link></li>
72+
<li><router-link :to="{ name: 'param', params: { q: 'A%' }}">/query/A% (object)</router-link></li>
73+
<li><router-link to="/query/A%2FE">/query/A%2FE</router-link></li>
74+
<li><router-link :to="{ name: 'param', params: { q: 'A/E' }}">/query/A%2FE (object)</router-link></li>
7275
</ul>
7376
<pre id="query-t">{{ $route.query.t }}</pre>
7477
<pre id="hash">{{ $route.hash }}</pre>
7578
<router-view class="view"></router-view>
7679
</div>
7780
`,
78-
methods: {
79-
}
81+
methods: {}
8082
}).$mount('#app')
8183

8284
document.getElementById('unmount').addEventListener('click', () => {

‎src/create-matcher.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,14 @@ function matchRoute (
175175
path: string,
176176
params: Object
177177
): boolean {
178-
const m = decodeURI(path).match(regex)
178+
let m
179+
try {
180+
m = decodeURI(path).match(regex)
181+
} catch (err) {
182+
if (process.env.NODE_ENV !== 'production') {
183+
warn(`Error decoding "${path}". Leaving it intact.`)
184+
}
185+
}
179186

180187
if (!m) {
181188
return false

‎src/util/query.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ const encode = str =>
1414
.replace(encodeReserveRE, encodeReserveReplacer)
1515
.replace(commaRE, ',')
1616

17-
const decode = decodeURIComponent
17+
export function decode (str) {
18+
try {
19+
return decodeURIComponent(str)
20+
} catch (err) {
21+
if (process.env.NODE_ENV !== 'production') {
22+
warn(`Error decoding "${str}". Leaving it intact.`)
23+
}
24+
}
25+
return str
26+
}
1827

1928
export function resolveQuery (
2029
query: ?string,

‎test/e2e/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (args.indexOf('-c') < 0) {
6161
function adaptArgv (argv) {
6262
// take every remaining argument and treat it as a test file
6363
// this allows to run `node test/e2e/runner.js test/e2e/basic.js`
64-
argv.retries = 1
64+
argv.retries = process.env.CI ? 1 : 0
6565
argv.test = argv['_'].slice(0)
6666

6767
if (argv.c === DEFAULT_CONFIG && argv.config === DEFAULT_CONFIG) {

0 commit comments

Comments
 (0)