Skip to content

Commit

Permalink
Merge branch 'patch-1' of https://github.com/hmate9/history
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson authored and peng.yang committed Aug 12, 2019
1 parent 038a412 commit b1423c6
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
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
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 b1423c6

Please sign in to comment.