diff --git a/src/util.js b/src/util.js index c2f30918d..7057ebb6b 100644 --- a/src/util.js +++ b/src/util.js @@ -85,6 +85,8 @@ function assert(cond, msg) { // Combines two URLs. The baseUrl shall be absolute URL. If the url is an // absolute URL, it will be returned as is. function combineUrl(baseUrl, url) { + if (!url) + return baseUrl; if (url.indexOf(':') >= 0) return url; if (url.charAt(0) == '/') { diff --git a/test/unit/util_spec.js b/test/unit/util_spec.js index c5743d6cc..d1f5a7387 100644 --- a/test/unit/util_spec.js +++ b/test/unit/util_spec.js @@ -45,6 +45,22 @@ describe('util', function() { var expected = 'http://server/test2.html'; expect(result).toEqual(expected); }); + + it('returns base url when url is empty', function() { + var baseUrl = 'http://server/index.html'; + var url = ''; + var result = combineUrl(baseUrl, url); + var expected = 'http://server/index.html'; + expect(result).toEqual(expected); + }); + + it('returns base url when url is undefined', function() { + var baseUrl = 'http://server/index.html'; + var url; + var result = combineUrl(baseUrl, url); + var expected = 'http://server/index.html'; + expect(result).toEqual(expected); + }); }); });