Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #544
Fixes #566
Fixes #608
  • Loading branch information
mjackson committed Mar 27, 2019
1 parent 2d8bb51 commit baef934
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 4 additions & 1 deletion modules/PathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export function stripLeadingSlash(path) {
}

export function hasBasename(path, prefix) {
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
return (
path.toLowerCase().indexOf(prefix.toLowerCase()) === 0 &&
'/?#'.indexOf(path.charAt(prefix.length)) !== -1
);
}

export function stripBasename(path, prefix) {
Expand Down
22 changes: 10 additions & 12 deletions modules/__tests__/HashHistory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ describe('a hash history', () => {

let history;
beforeEach(() => {
history = createHistory({
getUserConfirmation
});
history = createHistory({ getUserConfirmation });
});

it('receives the next location and action as arguments', done => {
Expand All @@ -184,9 +182,7 @@ describe('a hash history', () => {
describe('"hashbang" hash path coding', () => {
let history;
beforeEach(() => {
history = createHistory({
hashType: 'hashbang'
});
history = createHistory({ hashType: 'hashbang' });
});

it('properly encodes and decodes window.location.hash', done => {
Expand All @@ -197,9 +193,7 @@ describe('a hash history', () => {
describe('"noslash" hash path coding', () => {
let history;
beforeEach(() => {
history = createHistory({
hashType: 'noslash'
});
history = createHistory({ hashType: 'noslash' });
});

it('properly encodes and decodes window.location.hash', done => {
Expand All @@ -210,9 +204,7 @@ describe('a hash history', () => {
describe('"slash" hash path coding', () => {
let history;
beforeEach(() => {
history = createHistory({
hashType: 'slash'
});
history = createHistory({ hashType: 'slash' });
});

it('properly encodes and decodes window.location.hash', done => {
Expand Down Expand Up @@ -256,5 +248,11 @@ describe('a hash history', () => {
const history = createHistory({ basename: '/prefix' });
expect(history.location.pathname).toEqual('/');
});

it('allows URL with regex special characters', () => {
window.location.hash = '/prefix$special/hello';
const history = createHistory({ basename: '/prefix$special' });
expect(history.location.pathname).toEqual('/hello');
});
});
});

0 comments on commit baef934

Please sign in to comment.