mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 18:25:37 +02:00
fix of combineUrl(baseUrl, url) in case of url - null, empty, undefined + unittests
This commit is contained in:
parent
1e7100db1e
commit
18da086b96
2 changed files with 18 additions and 0 deletions
|
@ -85,6 +85,8 @@ function assert(cond, msg) {
|
||||||
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an
|
// Combines two URLs. The baseUrl shall be absolute URL. If the url is an
|
||||||
// absolute URL, it will be returned as is.
|
// absolute URL, it will be returned as is.
|
||||||
function combineUrl(baseUrl, url) {
|
function combineUrl(baseUrl, url) {
|
||||||
|
if (!url)
|
||||||
|
return baseUrl;
|
||||||
if (url.indexOf(':') >= 0)
|
if (url.indexOf(':') >= 0)
|
||||||
return url;
|
return url;
|
||||||
if (url.charAt(0) == '/') {
|
if (url.charAt(0) == '/') {
|
||||||
|
|
|
@ -45,6 +45,22 @@ describe('util', function() {
|
||||||
var expected = 'http://server/test2.html';
|
var expected = 'http://server/test2.html';
|
||||||
expect(result).toEqual(expected);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue