From 5df188e0a05621a15e1744fe57286297b978d892 Mon Sep 17 00:00:00 2001 From: tormozz48 Date: Wed, 25 Jan 2017 15:47:49 +0300 Subject: [PATCH] fix: Fix url decoration for urls without pathnames --- lib/browser.js | 2 +- test/lib/browser.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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()