Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge 030b67d into 036b32e
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturszott committed Oct 26, 2015
2 parents 036b32e + 030b67d commit 20e9347
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict';

var EVENT_POPSTATE = 'popstate';
var url = require('url');

function isUndefined(v) {
return v === undefined;
Expand Down Expand Up @@ -74,6 +75,8 @@ History.prototype = {
var state = this.getState();
var urlFromState = state && state.origUrl;
var location = this.win.location;
var baseURI = this.win.document.baseURI;
var strippedBaseURI;

if (urlFromState) {
// remove hostname from url
Expand All @@ -84,6 +87,12 @@ History.prototype = {
return urlFromState;
}

if (baseURI) {
strippedBaseURI = url.parse(baseURI).pathname.replace('/', '');

return location.pathname.substr(strippedBaseURI.length);
}

// fallback to what is the window.location
return location.pathname + location.search;
},
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/lib/History-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ describe('History', function () {
win.history.state.origUrl = 'https://foo.com:4080/';
expect(history.getUrl()).to.equal('/');
});
it('has pushState, should remove baseURI from window.location.pathname', function () {
var win = _.extend(windowMock.HTML5, {
history: {
state: {}
},
location: {
protocol: 'https:',
host: 'foo.com:4080',
pathname: '/base/path/to/page',
search: '',
hash: ''
},
document: {
baseURI: 'https://foo.com:4080/base/'
}
});
var history = new History({win: win});

expect(history.getUrl()).to.equal('/path/to/page');

win.document.baseURI = 'https://foo.com:4080/base/long/';
win.location.pathname = '/base/long/';
expect(history.getUrl()).to.equal('/');

win.document.baseURI = 'https://foo.com:4080/base/long/';
win.location.pathname = '/base/long/path/to/page';
expect(history.getUrl()).to.equal('/path/to/page');
});
it ('has pushState with query', function () {
var win = _.extend(windowMock.HTML5, {
location: {
Expand Down

0 comments on commit 20e9347

Please sign in to comment.