]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add test for slash encoding in catchAll
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 28 May 2020 21:43:18 +0000 (23:43 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 28 May 2020 21:43:18 +0000 (23:43 +0200)
__tests__/router.spec.ts
src/scrollBehavior.ts

index c9ed9823bda36dad362864d9999012955f64ad15..76425d60da51fe0ad7d58475f1fbfac01620f9f6 100644 (file)
@@ -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()
 
index 8417480ca7dbd629e09348de73fc2e5a4cc5e56f..606b7b9487c177e5cb28003cb07a3dc9ac6961d4 100644 (file)
@@ -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<T> {
-//   compute(): T
-//   scroll(position: T): void
+// export interface ScrollHandler<ScrollPositionEntry extends HistoryStateValue, ScrollPosition extends ScrollPositionEntry> {
+//   // 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<ScrollPosition> = {