From 205d7ccfab7d5537396c2660e0ace9746f768bd2 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 13 Dec 2021 10:24:36 -0500 Subject: [PATCH 01/16] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b1642ac7..8cb385bb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/v5.2.0-noslash.2.0). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/history/tree/publish-noslash). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). + # history · [![npm package][npm-badge]][npm] [![Travis][build-badge]][build] [npm-badge]: https://img.shields.io/npm/v/history.svg?style=flat-square From 5a3bf6bef9be1f28e39fe0125745219233c59e34 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 13 Dec 2021 10:25:34 -0500 Subject: [PATCH 02/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8cb385bb..c4988533 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/v5.2.0-noslash.2.0). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/history/tree/publish-noslash). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). +For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/v5.2.0-noslash.2.0). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/test-history-router#history-router-test-template). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). # history · [![npm package][npm-badge]][npm] [![Travis][build-badge]][build] From abb562501672866335fd269cbb05347f9a79c180 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 13 Dec 2021 10:26:36 -0500 Subject: [PATCH 03/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4988533..57440b02 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/v5.2.0-noslash.2.0). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/test-history-router#history-router-test-template). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). +For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/v5.2.0-noslash.2.2#history-noslash). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/test-history-router#history-router-test-template). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). # history · [![npm package][npm-badge]][npm] [![Travis][build-badge]][build] From e796aebfa2d5566f39a4e221629243c902df0d74 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 13 Dec 2021 10:27:25 -0500 Subject: [PATCH 04/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57440b02..d3956c71 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/v5.2.0-noslash.2.2#history-noslash). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/test-history-router#history-router-test-template). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). +For this fork, here is the [published branch](https://github.com/thejohnhoffer/history/tree/publish-noslash#history-noslash). That branch is a response to [history issue 912](https://github.com/remix-run/history/issues/912), and here's [a template for its use](https://github.com/thejohnhoffer/test-history-router#history-router-test-template). It can be installed as `history-noslash` from `npm` and `yarn` [here](https://yarnpkg.com/package/history-noslash#readme). # history · [![npm package][npm-badge]][npm] [![Travis][build-badge]][build] From 59580ad9671015e8db9d813aea4e95f69b0c65f4 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 20 Dec 2021 11:12:24 -0500 Subject: [PATCH 05/16] simple solution for hashRoot parsing --- packages/history/index.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/history/index.ts b/packages/history/index.ts index e38d9bbc..6c71bbdf 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -573,7 +573,7 @@ export function createBrowserHistory( // HASH //////////////////////////////////////////////////////////////////////////////// -export type HashHistoryOptions = { window?: Window }; +export type HashHistoryOptions = { window?: Window, hashRoot?: string }; /** * Hash history stores the location in window.location.hash. This makes it ideal @@ -589,12 +589,26 @@ export function createHashHistory( let { window = document.defaultView! } = options; let globalHistory = window.history; + let { hashRoot = "/" } = options; + + function parsePathInput(pathname) { + return parsePath(pathname.replace(hashRoot, "/")); + } + + function parsePathOutput(pathname) { + return parsePath(pathname.replace(/^\//, hashRoot)); + } + + function validateLocation({pathname}) { + return pathname === parsePathOutput(pathname) + } + function getIndexAndLocation(): [number, Location] { let { pathname = '/', search = '', hash = '' - } = parsePath(window.location.hash.substr(1)); + } = parsePathInput(window.location.hash.substr(1)); let state = globalHistory.state || {}; return [ state.idx, @@ -698,7 +712,7 @@ export function createHashHistory( pathname: location.pathname, hash: '', search: '', - ...(typeof to === 'string' ? parsePath(to) : to), + ...(typeof to === 'string' ? parsePathOutput(to) : to), state, key: createKey() }); @@ -738,8 +752,8 @@ export function createHashHistory( } warning( - nextLocation.pathname.charAt(0) === '/', - `Relative pathnames are not supported in hash history.push(${JSON.stringify( + validateLocation(nextLocation), + `Locations must start with "${hashRoot}" in hash history.push(${JSON.stringify( to )})` ); @@ -769,8 +783,8 @@ export function createHashHistory( } warning( - nextLocation.pathname.charAt(0) === '/', - `Relative pathnames are not supported in hash history.replace(${JSON.stringify( + validateLocation(nextLocation), + `Locations must start with "${hashRoot}" in hash history.replace(${JSON.stringify( to )})` ); From 34db1b5878b8cf284f12d6b7adff93b14e6caf35 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 20 Dec 2021 11:42:43 -0500 Subject: [PATCH 06/16] add basic tests for hashRoot="" --- .../TestSequences/PushRelativePathnameWarning.js | 4 +--- packages/history/__tests__/hash-root-test.js | 8 ++++++++ packages/history/__tests__/hash-test.js | 12 +++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 packages/history/__tests__/hash-root-test.js diff --git a/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js b/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js index 85cb9bc2..d2bbd525 100644 --- a/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js +++ b/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js @@ -23,9 +23,7 @@ export default (history, done) => { history.push('../other/path?another=query#another-hash'); - expect(spy).toHaveBeenCalledWith( - expect.stringContaining('relative pathnames are not supported') - ); + expect(spy).toHaveBeenCalled(); destroy(); }, diff --git a/packages/history/__tests__/hash-root-test.js b/packages/history/__tests__/hash-root-test.js new file mode 100644 index 00000000..13dbbc2a --- /dev/null +++ b/packages/history/__tests__/hash-root-test.js @@ -0,0 +1,8 @@ +import { createHashHistory } from 'history'; +import { testHashHistory } from './hash-test.js'; + +describe('a hash history with no slash', () => { + testHashHistory('#', () => { + return createHashHistory({hashRoot: ''}); + }) +}); diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index b528893e..db27a501 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -21,11 +21,11 @@ import BlockPopWithoutListening from './TestSequences/BlockPopWithoutListening.j // const canGoWithoutReload = window.navigator.userAgent.indexOf('Firefox') === -1; // const describeGo = canGoWithoutReload ? describe : describe.skip; -describe('a hash history', () => { +export const testHashHistory = (root, createHistory) => { let history; beforeEach(() => { - window.history.replaceState(null, null, '#/'); - history = createHashHistory(); + window.history.replaceState(null, null, root); + history = createHistory() }); it('knows how to create hrefs from location objects', () => { @@ -144,4 +144,10 @@ describe('a hash history', () => { BlockPopWithoutListening(history, done); }); }); +} + +describe('a hash history', () => { + testHashHistory('#/', () => { + return createHashHistory(); + }) }); From 78da42be600968d507d2300b0eadcce6edd478cb Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 20 Dec 2021 13:19:28 -0500 Subject: [PATCH 07/16] simplify further --- packages/history/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/history/index.ts b/packages/history/index.ts index 6c71bbdf..3ad75c10 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -589,14 +589,14 @@ export function createHashHistory( let { window = document.defaultView! } = options; let globalHistory = window.history; - let { hashRoot = "/" } = options; + let { hashRoot = '/' } = options; function parsePathInput(pathname) { - return parsePath(pathname.replace(hashRoot, "/")); + return parsePath(pathname.replace(hashRoot, '/')); } function parsePathOutput(pathname) { - return parsePath(pathname.replace(/^\//, hashRoot)); + return parsePath(pathname.replace('/', hashRoot)); } function validateLocation({pathname}) { From 45e710eae201e3e85ab0735b59929ff8b37fb8c8 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 20 Dec 2021 13:19:45 -0500 Subject: [PATCH 08/16] improve tests --- packages/history/__tests__/hash-root-test.js | 18 ++++++++++++++++-- packages/history/__tests__/hash-test.js | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/history/__tests__/hash-root-test.js b/packages/history/__tests__/hash-root-test.js index 13dbbc2a..37d730e1 100644 --- a/packages/history/__tests__/hash-root-test.js +++ b/packages/history/__tests__/hash-root-test.js @@ -1,8 +1,22 @@ -import { createHashHistory } from 'history'; +import expect from 'expect'; +import { createHashHistory, createPath } from 'history'; import { testHashHistory } from './hash-test.js'; describe('a hash history with no slash', () => { testHashHistory('#', () => { - return createHashHistory({hashRoot: ''}); + const history = createHashHistory({hashRoot: ''}); + + // Test window location at every step + return new Proxy(history, { + get(target, prop, _) { + if (prop === 'location') { + const historyHref = createPath(history.location) + const windowHref = window.location.hash.substr(1) + expect(historyHref.replace('/','')).toEqual(windowHref); + expect(historyHref).toEqual(windowHref.replace('', '/')); + } + return Reflect.get(target, prop, _); + } + }); }) }); diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index db27a501..38ad0c9f 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -146,8 +146,10 @@ export const testHashHistory = (root, createHistory) => { }); } +/* describe('a hash history', () => { testHashHistory('#/', () => { return createHashHistory(); }) }); +*/ From f595287b6a9ee1e154fb25ebf2ff3545a9b5ba26 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 20 Dec 2021 13:21:30 -0500 Subject: [PATCH 09/16] restore original tests --- packages/history/__tests__/hash-test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index 38ad0c9f..db27a501 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -146,10 +146,8 @@ export const testHashHistory = (root, createHistory) => { }); } -/* describe('a hash history', () => { testHashHistory('#/', () => { return createHashHistory(); }) }); -*/ From 2bf3314217e3b7ae17198488658c4231f1738f11 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Mon, 20 Dec 2021 13:42:42 -0500 Subject: [PATCH 10/16] use original PushRelativePathnameWarning test --- .../TestSequences/PushRelativePathnameWarning.js | 4 +++- packages/history/index.ts | 12 ++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js b/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js index d2bbd525..85cb9bc2 100644 --- a/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js +++ b/packages/history/__tests__/TestSequences/PushRelativePathnameWarning.js @@ -23,7 +23,9 @@ export default (history, done) => { history.push('../other/path?another=query#another-hash'); - expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith( + expect.stringContaining('relative pathnames are not supported') + ); destroy(); }, diff --git a/packages/history/index.ts b/packages/history/index.ts index 3ad75c10..2efc752a 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -599,10 +599,6 @@ export function createHashHistory( return parsePath(pathname.replace('/', hashRoot)); } - function validateLocation({pathname}) { - return pathname === parsePathOutput(pathname) - } - function getIndexAndLocation(): [number, Location] { let { pathname = '/', @@ -752,8 +748,8 @@ export function createHashHistory( } warning( - validateLocation(nextLocation), - `Locations must start with "${hashRoot}" in hash history.push(${JSON.stringify( + nextLocation.pathname.charAt(0) === '/', + `Relative pathnames are not supported in hash history.push(${JSON.stringify( to )})` ); @@ -783,8 +779,8 @@ export function createHashHistory( } warning( - validateLocation(nextLocation), - `Locations must start with "${hashRoot}" in hash history.replace(${JSON.stringify( + nextLocation.pathname.charAt(0) === '/', + `Relative pathnames are not supported in hash history.replace(${JSON.stringify( to )})` ); From 821d40c80678afc1e58135d1b6a5703d80babe98 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Tue, 21 Dec 2021 07:00:06 -0500 Subject: [PATCH 11/16] handle all possible types for To --- packages/history/__tests__/hash-root-test.js | 2 +- packages/history/__tests__/hash-test.js | 2 +- packages/history/index.ts | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/history/__tests__/hash-root-test.js b/packages/history/__tests__/hash-root-test.js index 37d730e1..61b2f37b 100644 --- a/packages/history/__tests__/hash-root-test.js +++ b/packages/history/__tests__/hash-root-test.js @@ -18,5 +18,5 @@ describe('a hash history with no slash', () => { return Reflect.get(target, prop, _); } }); - }) + }) }); diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index db27a501..232eb453 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -149,5 +149,5 @@ export const testHashHistory = (root, createHistory) => { describe('a hash history', () => { testHashHistory('#/', () => { return createHashHistory(); - }) + }) }); diff --git a/packages/history/index.ts b/packages/history/index.ts index 2efc752a..b25e36a1 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -591,20 +591,19 @@ export function createHashHistory( let { hashRoot = '/' } = options; - function parsePathInput(pathname) { - return parsePath(pathname.replace(hashRoot, '/')); - } - - function parsePathOutput(pathname) { - return parsePath(pathname.replace('/', hashRoot)); + function prefixPathname([base, root]: string[], partial: Partial) { + const pathname = (partial.pathname || base).replace(base, root); + return { pathname, ...partial }; } + const pathFromGlobal = prefixPathname.bind(null, [hashRoot, '/']); + const pathToGlobal = prefixPathname.bind(null, ['/', hashRoot]); function getIndexAndLocation(): [number, Location] { let { pathname = '/', search = '', hash = '' - } = parsePathInput(window.location.hash.substr(1)); + } = pathFromGlobal(parsePath(window.location.hash.substr(1))) let state = globalHistory.state || {}; return [ state.idx, @@ -708,7 +707,7 @@ export function createHashHistory( pathname: location.pathname, hash: '', search: '', - ...(typeof to === 'string' ? parsePathOutput(to) : to), + ...(typeof to === 'string' ? parsePath(to) : to), state, key: createKey() }); @@ -724,7 +723,7 @@ export function createHashHistory( key: nextLocation.key, idx: index }, - createHref(nextLocation) + createHref(pathToGlobal(nextLocation)) ]; } From 51a33ef9d470f177f4aaf9f5e0cbc8a717715f0c Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Tue, 21 Dec 2021 07:21:34 -0500 Subject: [PATCH 12/16] improve tests --- packages/history/__tests__/hash-root-test.js | 18 +--------------- packages/history/__tests__/hash-test.js | 22 +++++++++++++------- packages/history/index.ts | 2 +- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/packages/history/__tests__/hash-root-test.js b/packages/history/__tests__/hash-root-test.js index 61b2f37b..26d8cf57 100644 --- a/packages/history/__tests__/hash-root-test.js +++ b/packages/history/__tests__/hash-root-test.js @@ -1,22 +1,6 @@ import expect from 'expect'; -import { createHashHistory, createPath } from 'history'; import { testHashHistory } from './hash-test.js'; describe('a hash history with no slash', () => { - testHashHistory('#', () => { - const history = createHashHistory({hashRoot: ''}); - - // Test window location at every step - return new Proxy(history, { - get(target, prop, _) { - if (prop === 'location') { - const historyHref = createPath(history.location) - const windowHref = window.location.hash.substr(1) - expect(historyHref.replace('/','')).toEqual(windowHref); - expect(historyHref).toEqual(windowHref.replace('', '/')); - } - return Reflect.get(target, prop, _); - } - }); - }) + testHashHistory('#', {hashRoot: ""}) }); diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index 232eb453..80799609 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -1,5 +1,5 @@ import expect from 'expect'; -import { createHashHistory } from 'history'; +import { createHashHistory, createPath } from 'history'; import Listen from './TestSequences/Listen.js'; import InitialLocationDefaultKey from './TestSequences/InitialLocationDefaultKey.js'; @@ -21,12 +21,20 @@ import BlockPopWithoutListening from './TestSequences/BlockPopWithoutListening.j // const canGoWithoutReload = window.navigator.userAgent.indexOf('Firefox') === -1; // const describeGo = canGoWithoutReload ? describe : describe.skip; -export const testHashHistory = (root, createHistory) => { +export const testHashHistory = (initialRoot, options) => { let history; beforeEach(() => { - window.history.replaceState(null, null, root); - history = createHistory() - }); + window.history.replaceState(null, null, initialRoot); + history = createHashHistory(options); + }); + afterEach(() => { + // Test window location at every step + const { hashRoot = "/" } = options || {}; + const historyHref = createPath(history.location); + const windowHref = window.location.hash.substr(1); + expect(historyHref.replace('/', hashRoot)).toEqual(windowHref); + expect(historyHref).toEqual(windowHref.replace(hashRoot, '/')); + }) it('knows how to create hrefs from location objects', () => { const href = history.createHref({ @@ -147,7 +155,5 @@ export const testHashHistory = (root, createHistory) => { } describe('a hash history', () => { - testHashHistory('#/', () => { - return createHashHistory(); - }) + testHashHistory('#/') }); diff --git a/packages/history/index.ts b/packages/history/index.ts index b25e36a1..8b1b336f 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -603,7 +603,7 @@ export function createHashHistory( pathname = '/', search = '', hash = '' - } = pathFromGlobal(parsePath(window.location.hash.substr(1))) + } = pathFromGlobal(parsePath(window.location.hash.substr(1))); let state = globalHistory.state || {}; return [ state.idx, From 077cc5fc35915cd20307e30462d07adee7b95be0 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Tue, 21 Dec 2021 07:42:48 -0500 Subject: [PATCH 13/16] minor change to ensure pathname overwrites --- packages/history/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/history/index.ts b/packages/history/index.ts index 8b1b336f..330f8cf7 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -593,7 +593,7 @@ export function createHashHistory( function prefixPathname([base, root]: string[], partial: Partial) { const pathname = (partial.pathname || base).replace(base, root); - return { pathname, ...partial }; + return { ...partial, pathname }; } const pathFromGlobal = prefixPathname.bind(null, [hashRoot, '/']); const pathToGlobal = prefixPathname.bind(null, ['/', hashRoot]); From 102165a7ba37f4721dd0678281435252677579e2 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Tue, 21 Dec 2021 09:09:58 -0500 Subject: [PATCH 14/16] handle relative pathnames --- packages/history/__tests__/hash-test.js | 3 +-- packages/history/index.ts | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/history/__tests__/hash-test.js b/packages/history/__tests__/hash-test.js index 80799609..8c183c67 100644 --- a/packages/history/__tests__/hash-test.js +++ b/packages/history/__tests__/hash-test.js @@ -32,8 +32,7 @@ export const testHashHistory = (initialRoot, options) => { const { hashRoot = "/" } = options || {}; const historyHref = createPath(history.location); const windowHref = window.location.hash.substr(1); - expect(historyHref.replace('/', hashRoot)).toEqual(windowHref); - expect(historyHref).toEqual(windowHref.replace(hashRoot, '/')); + expect(historyHref.replace(/^\//, hashRoot)).toEqual(windowHref); }) it('knows how to create hrefs from location objects', () => { diff --git a/packages/history/index.ts b/packages/history/index.ts index 330f8cf7..00663f20 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -592,8 +592,11 @@ export function createHashHistory( let { hashRoot = '/' } = options; function prefixPathname([base, root]: string[], partial: Partial) { - const pathname = (partial.pathname || base).replace(base, root); - return { ...partial, pathname }; + const input = partial.pathname || base; + const pathname = input.replace(base, root); + return input.match(/^\.+\//) ? partial : { + ...partial, pathname + }; } const pathFromGlobal = prefixPathname.bind(null, [hashRoot, '/']); const pathToGlobal = prefixPathname.bind(null, ['/', hashRoot]); From ec995a277b3ac30a03e9d2f32486efbe6b4d9f53 Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Tue, 21 Dec 2021 08:57:46 -0600 Subject: [PATCH 15/16] one fewer line --- packages/history/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/history/index.ts b/packages/history/index.ts index 00663f20..2bacd722 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -593,9 +593,8 @@ export function createHashHistory( function prefixPathname([base, root]: string[], partial: Partial) { const input = partial.pathname || base; - const pathname = input.replace(base, root); return input.match(/^\.+\//) ? partial : { - ...partial, pathname + ...partial, pathname: input.replace(base, root) }; } const pathFromGlobal = prefixPathname.bind(null, [hashRoot, '/']); From 7f8c9d9d123a170d4c2f24e2e4e23657df7aabbb Mon Sep 17 00:00:00 2001 From: John Hoffer Date: Tue, 21 Dec 2021 09:21:54 -0600 Subject: [PATCH 16/16] only ignore prefix when path matches ../ --- packages/history/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/history/index.ts b/packages/history/index.ts index 2bacd722..b41823b2 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -593,7 +593,7 @@ export function createHashHistory( function prefixPathname([base, root]: string[], partial: Partial) { const input = partial.pathname || base; - return input.match(/^\.+\//) ? partial : { + return input.match(/^\.\.\//) ? partial : { ...partial, pathname: input.replace(base, root) }; }