]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: match base in a non-sensitive way
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 10 May 2020 11:41:47 +0000 (13:41 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 10 May 2020 11:50:48 +0000 (13:50 +0200)
__tests__/location.spec.ts
src/history/memory.ts
src/location.ts

index e03849506834699c7693e1806d05840c7bd11553..b3738077ca82e757f04b123f5fb8e9af58d557a8 100644 (file)
@@ -227,6 +227,15 @@ describe('stripBase', () => {
     expect(stripBase('/thing', '')).toBe('/thing')
   })
 
+  it('is case insensitive', () => {
+    expect(stripBase('/Base/foo', '/base')).toBe('/foo')
+    expect(stripBase('/Basé/foo', '/base')).toBe('/Basé/foo')
+    expect(stripBase('/Basé/foo', '/basé')).toBe('/foo')
+    expect(stripBase('/base/foo', '/Base')).toBe('/foo')
+    expect(stripBase('/base/foo', '/Basé')).toBe('/base/foo')
+    expect(stripBase('/basé/foo', '/Basé')).toBe('/foo')
+  })
+
   it('returns the pathname without the base', () => {
     expect(stripBase('/base', '/base')).toBe('/')
     expect(stripBase('/base/', '/base')).toBe('/')
index dad5fbd78126c15c23e62ed93f3638da3284fb20..f24c4e446cd419aeda09c1d1378e764574837b45 100644 (file)
@@ -10,6 +10,8 @@ import {
   NavigationInformation,
 } from './common'
 
+// TODO: verify base is working for SSR
+
 /**
  * Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere.
  * It's up to the user to replace that location with the starter location.
index 9b56130baa789c410b96cc68746fe6a7573347b7..4e650708a5002f4bf2d9820ad1802a44c2a99b02 100644 (file)
@@ -105,15 +105,17 @@ export function stringifyURL(
 }
 
 /**
- * Strips off the base from the beginning of a location.pathname
+ * Strips off the base from the beginning of a location.pathname in a non
+ * case-sensitive way.
  *
  * @param pathname - location.pathname
  * @param base - base to strip off
  */
 export function stripBase(pathname: string, base: string): string {
-  // no base or base is not found at the begining
-  if (!base || pathname.indexOf(base)) return pathname
-  return pathname.replace(base, '') || '/'
+  // no base or base is not found at the beginning
+  if (!base || pathname.toLowerCase().indexOf(base.toLowerCase()))
+    return pathname
+  return pathname.slice(base.length) || '/'
 }
 
 /**