From: Eduardo San Martin Morote Date: Thu, 28 May 2020 21:43:18 +0000 (+0200) Subject: test: add test for slash encoding in catchAll X-Git-Tag: v4.0.0-alpha.13~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcbd8d97e0625592416f78b2cfca9875c377d791;p=thirdparty%2Fvuejs%2Frouter.git test: add test for slash encoding in catchAll --- diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index c9ed9823..76425d60 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -322,6 +322,40 @@ describe('Router', () => { expect(() => router.resolve({ name: 'r2', params: {} })).not.toThrow() }) + it('can redirect to a star route when encoding the param', () => { + const history = createMemoryHistory() + const router = createRouter({ + history, + routes: [ + { name: 'notfound', path: '/:path(.*)+', component: components.Home }, + ], + }) + let path = 'not/found%2Fha' + let href = '/' + path + expect(router.resolve(href)).toMatchObject({ + name: 'notfound', + fullPath: href, + path: href, + href: href, + }) + expect( + router.resolve({ + name: 'notfound', + params: { + path: path + .split('/') + // we need to provide the value unencoded + .map(segment => segment.replace('%2F', '/')), + }, + }) + ).toMatchObject({ + name: 'notfound', + fullPath: href, + path: href, + href: href, + }) + }) + describe('Warnings', () => { mockWarn() diff --git a/src/scrollBehavior.ts b/src/scrollBehavior.ts index 8417480c..606b7b94 100644 --- a/src/scrollBehavior.ts +++ b/src/scrollBehavior.ts @@ -32,7 +32,8 @@ export type _ScrollPositionNormalized = { export interface ScrollPositionElement { /** - * A simple _id_ selector with a leading `#` or a valid CSS selector **not starting** with a `#`. + * A valid CSS selector. + * * @example * Here are a few examples: * @@ -131,7 +132,10 @@ export function scrollToPosition(position: ScrollPosition): void { if ('scrollBehavior' in document.documentElement.style) window.scrollTo(scrollToOptions) - else window.scrollTo(scrollToOptions.left || 0, scrollToOptions.top || 0) + else { + // TODO: pass the current value instead of 0 using computeScroll + window.scrollTo(scrollToOptions.left || 0, scrollToOptions.top || 0) + } } export function getScrollKey(path: string, delta: number): string { @@ -160,9 +164,11 @@ export function getSavedScrollPosition(key: string) { * ScrollBehavior instance used by the router to compute and restore the scroll * position when navigating. */ -// export interface ScrollHandler { -// compute(): T -// scroll(position: T): void +// export interface ScrollHandler { +// // returns a scroll position that can be saved in history +// compute(): ScrollPositionEntry +// // can take an extended ScrollPositionEntry +// scroll(position: ScrollPosition): void // } // export const scrollHandler: ScrollHandler = {