Skip to content

Commit bcbd8d9

Browse files
committed
test: add test for slash encoding in catchAll
1 parent 74b155b commit bcbd8d9

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

__tests__/router.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,40 @@ describe('Router', () => {
322322
expect(() => router.resolve({ name: 'r2', params: {} })).not.toThrow()
323323
})
324324

325+
it('can redirect to a star route when encoding the param', () => {
326+
const history = createMemoryHistory()
327+
const router = createRouter({
328+
history,
329+
routes: [
330+
{ name: 'notfound', path: '/:path(.*)+', component: components.Home },
331+
],
332+
})
333+
let path = 'not/found%2Fha'
334+
let href = '/' + path
335+
expect(router.resolve(href)).toMatchObject({
336+
name: 'notfound',
337+
fullPath: href,
338+
path: href,
339+
href: href,
340+
})
341+
expect(
342+
router.resolve({
343+
name: 'notfound',
344+
params: {
345+
path: path
346+
.split('/')
347+
// we need to provide the value unencoded
348+
.map(segment => segment.replace('%2F', '/')),
349+
},
350+
})
351+
).toMatchObject({
352+
name: 'notfound',
353+
fullPath: href,
354+
path: href,
355+
href: href,
356+
})
357+
})
358+
325359
describe('Warnings', () => {
326360
mockWarn()
327361

src/scrollBehavior.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export type _ScrollPositionNormalized = {
3232

3333
export interface ScrollPositionElement {
3434
/**
35-
* A simple _id_ selector with a leading `#` or a valid CSS selector **not starting** with a `#`.
35+
* A valid CSS selector.
36+
*
3637
* @example
3738
* Here are a few examples:
3839
*
@@ -131,7 +132,10 @@ export function scrollToPosition(position: ScrollPosition): void {
131132

132133
if ('scrollBehavior' in document.documentElement.style)
133134
window.scrollTo(scrollToOptions)
134-
else window.scrollTo(scrollToOptions.left || 0, scrollToOptions.top || 0)
135+
else {
136+
// TODO: pass the current value instead of 0 using computeScroll
137+
window.scrollTo(scrollToOptions.left || 0, scrollToOptions.top || 0)
138+
}
135139
}
136140

137141
export function getScrollKey(path: string, delta: number): string {
@@ -160,9 +164,11 @@ export function getSavedScrollPosition(key: string) {
160164
* ScrollBehavior instance used by the router to compute and restore the scroll
161165
* position when navigating.
162166
*/
163-
// export interface ScrollHandler<T> {
164-
// compute(): T
165-
// scroll(position: T): void
167+
// export interface ScrollHandler<ScrollPositionEntry extends HistoryStateValue, ScrollPosition extends ScrollPositionEntry> {
168+
// // returns a scroll position that can be saved in history
169+
// compute(): ScrollPositionEntry
170+
// // can take an extended ScrollPositionEntry
171+
// scroll(position: ScrollPosition): void
166172
// }
167173

168174
// export const scrollHandler: ScrollHandler<ScrollPosition> = {

0 commit comments

Comments
 (0)