Skip to content

Commit 80f8f51

Browse files
committed
Merge pull request mozilla#2400 from khodzha/2279_issue
combineUrl fix
2 parents 73c8d86 + 18da086 commit 80f8f51

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function assert(cond, msg) {
8585
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an
8686
// absolute URL, it will be returned as is.
8787
function combineUrl(baseUrl, url) {
88+
if (!url)
89+
return baseUrl;
8890
if (url.indexOf(':') >= 0)
8991
return url;
9092
if (url.charAt(0) == '/') {

test/unit/util_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ describe('util', function() {
4545
var expected = 'http://server/test2.html';
4646
expect(result).toEqual(expected);
4747
});
48+
49+
it('returns base url when url is empty', function() {
50+
var baseUrl = 'http://server/index.html';
51+
var url = '';
52+
var result = combineUrl(baseUrl, url);
53+
var expected = 'http://server/index.html';
54+
expect(result).toEqual(expected);
55+
});
56+
57+
it('returns base url when url is undefined', function() {
58+
var baseUrl = 'http://server/index.html';
59+
var url;
60+
var result = combineUrl(baseUrl, url);
61+
var expected = 'http://server/index.html';
62+
expect(result).toEqual(expected);
63+
});
4864
});
4965

5066
});

0 commit comments

Comments
 (0)