diff --git a/lib/browser.js b/lib/browser.js index 1137590a6..fd964e6e4 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -145,7 +145,7 @@ module.exports = class Browser { } _getMetaUrl(uri) { - return this._config.baseUrl && uri[0] === '/' + return this._config.baseUrl && /^(\/|\?)/.test(uri) ? URI(this._config.baseUrl + uri).normalize().toString() : uri; } diff --git a/test/lib/browser.js b/test/lib/browser.js index d592e167f..9fef1d13a 100644 --- a/test/lib/browser.js +++ b/test/lib/browser.js @@ -216,7 +216,7 @@ describe('Browser', () => { }); }); - it('should add last url to meta-info', () => { + it('should add last url to meta-info if it starts from /', () => { return mkBrowser_({baseUrl: 'http://some.domain.org/root'}) .init() .then((browser) => { @@ -228,6 +228,16 @@ describe('Browser', () => { }); }); + it('should add last url to meta-info if it contains only query part', () => { + return mkBrowser_({baseUrl: 'http://some.domain.org/root'}) + .init() + .then((browser) => { + session.url('?baz=qux'); + + assert.equal(browser.meta.url, 'http://some.domain.org/root?baz=qux'); + }); + }); + it('should not concat url without slash at the beginning to the base url', () => { return mkBrowser_({baseUrl: 'http://some.domain.org'}) .init()