Skip to content

Commit

Permalink
fix(scheduler): ignore invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Jun 24, 2024
1 parent 58fc8bb commit c3a67a3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Core/Scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Scheduler.prototype.execute = function execute(command) {

// parse host
const layer = command.layer;
const host = layer.source && layer.source.url ?
const host = layer.source && layer.source.url && layer.source.url !== 'none' ?
new URL(URLBuilder.subDomains(layer.source.url), document.location).host : undefined;

command.promise = new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Source/FileSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class FileSource extends Source {
}

// the fake url is for when we use the fetchedData or features mode
source.url = source.url || 'fake-file-url';
source.url = source.url || 'none';
super(source);

this.isFileSource = true;
Expand Down
13 changes: 0 additions & 13 deletions test/unit/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ global.window = {
setTimeout,
};

global.URL = function URL(url) {
return {
host: url.split('://')[1]?.split('/')[0],
hostname: url.split('://')[1]?.split(':')[0],
port: url.split('://')[1]?.split(':')[1],
protocol: url.split('://')[0],
};
};

// https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-instanceofoperator
// ES standard requires that left-hand side shall have a prototype method, this
// is not the case for lambdas.
global.Event = function () {};
global.requestAnimationFrame = () => {};
global.fetch = fetch;
global.fetch.Promise = Promise;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/layeredmaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('material state vs layer state', function () {
before(function () {
stubFetcherTexture = sinon.stub(Fetcher, 'texture')
.callsFake(() => Promise.resolve(null));
const source = new TMSSource({ crs: 'EPSG:4326', url: 'nullUrl' });
const source = new TMSSource({ crs: 'EPSG:4326', url: 'http://tms.test' });
layer = new ColorLayer('color', {
source,
crs: 'EPSG:4326',
Expand Down
8 changes: 4 additions & 4 deletions test/unit/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Sources', function () {

describe('OrientedImageSource', function () {
it('instance OrientedImageSource', function (done) {
const source = new OrientedImageSource({ url: 'none' });
const source = new OrientedImageSource({ url: 'http://source.test' });
source.whenReady
.then((a) => {
assert.equal(Object.keys(a).length, 2);
Expand All @@ -183,7 +183,7 @@ describe('Sources', function () {
});

it('should return keys OrientedImageSource from request', function () {
const source = new OrientedImageSource({ url: 'none' });
const source = new OrientedImageSource({ url: 'http://source.test' });
const image = { cameraId: 5, panoId: 10 };
const keys = source.requestToKey(image);
assert.equal(image.cameraId, keys[0]);
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('Sources', function () {
});

assert.ok(!source.features);
assert.equal(source.urlFromExtent(), 'fake-file-url');
assert.equal(source.urlFromExtent(), 'none');
assert.ok(source.fetchedData);
assert.ok(source.isFileSource);

Expand Down Expand Up @@ -289,7 +289,7 @@ describe('Sources', function () {
format: 'application/json',
});
source.onLayerAdded({ out: { crs: source.crs } });
assert.ok(source.urlFromExtent(extent).startsWith('fake-file-url'));
assert.ok(source.urlFromExtent(extent).startsWith('none'));
assert.ok(!source.fetchedData);

assert.ok(source.isFileSource);
Expand Down

0 comments on commit c3a67a3

Please sign in to comment.