From: Eduardo San Martin Morote Date: Sun, 10 May 2020 11:41:47 +0000 (+0200) Subject: fix: match base in a non-sensitive way X-Git-Tag: v4.0.0-alpha.11~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7087bbc9c479f2955381d8a823a3ef8f9eed7b5a;p=thirdparty%2Fvuejs%2Frouter.git fix: match base in a non-sensitive way --- diff --git a/__tests__/location.spec.ts b/__tests__/location.spec.ts index e0384950..b3738077 100644 --- a/__tests__/location.spec.ts +++ b/__tests__/location.spec.ts @@ -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('/') diff --git a/src/history/memory.ts b/src/history/memory.ts index dad5fbd7..f24c4e44 100644 --- a/src/history/memory.ts +++ b/src/history/memory.ts @@ -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. diff --git a/src/location.ts b/src/location.ts index 9b56130b..4e650708 100644 --- a/src/location.ts +++ b/src/location.ts @@ -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) || '/' } /**