Skip to content

Commit

Permalink
disallow duplicate vector_layers by ID (#104)
Browse files Browse the repository at this point in the history
* error if duplicate layers are found

* es5 syntax

* 4.7.1-dev1

* add fixture

* 4.8.0

* update lockfile
  • Loading branch information
mapsam authored Sep 14, 2021
1 parent f1fa142 commit 007e958
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 74 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.8.0

* Reject MBTiles with duplicate `id` fields in the json vector_layers metadata array [#104](https://github.com/mapbox/mapbox-upload-validate/pull/104)

## 4.7.0

* Require mbtiles metadata maxzoom to match the tiles table maxzoom
Expand Down
15 changes: 12 additions & 3 deletions lib/validators/mbtiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ function validFormat(db, info, callback) {
var format = tiletype.type(result.tile_data);
if (!format) return callback(invalid('Unknown format.'));

if (format === 'pbf' && !info.hasOwnProperty('vector_layers'))
return callback(invalid('Vector source must include "vector_layers" key'));
if (format === 'pbf') {
if (!info.hasOwnProperty('vector_layers')) return callback(invalid('Vector source must include "vector_layers" key'));

// disallow duplicate layers by ID
var ids = [];
for (var i = 0; i < info.vector_layers.length; i++) {
var id = info.vector_layers[i].id;
if (ids.includes(id)) return callback(invalid('Vector source "vector_layers" contains duplicate ID: ' + id));
ids.push(info.vector_layers[i].id);
}
}

log.debug('validFormat(): valid!');
callback();
Expand Down Expand Up @@ -109,7 +118,7 @@ function zoomCheck(db, limits, callback) {
cb(null, result);
});
}

log.debug('zoomCheck(): checking...');
queue()
.defer(getMaxZoom, 'tiles_max')
Expand Down
136 changes: 68 additions & 68 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mapbox-upload-validate",
"version": "4.7.0",
"version": "4.8.0",
"description": "Validate that a file can be uploaded to Mapbox",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion test/expected/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ module.exports = {
'nulltile': 'Tile is invalid',
'prepare': 'Source cannot contain prepare key',
'filetoobig': 'File is larger than 1.02 kB. Too big to process.',
'zoomleveltoobig': 'Maxzoom exceeded for mbtiles file. There is a max zoom limit of 0 but tiles up to zoom level 1 were found. If you need support for 1cm tilesets please reach out to support.'
'zoomleveltoobig': 'Maxzoom exceeded for mbtiles file. There is a max zoom limit of 0 but tiles up to zoom level 1 were found. If you need support for 1cm tilesets please reach out to support.',
'duplicate_layers': 'Vector source "vector_layers" contains duplicate ID: apples'
},
unsupportedErrors: 'Unknown filetype'
};
3 changes: 2 additions & 1 deletion test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ module.exports = {
'empty': path.join(__dirname, 'invalid.mbtiles-empty.mbtiles'),
'limits': path.join(__dirname, 'invalid.mbtiles-limits.mbtiles'),
'nulltile': path.join(__dirname, 'invalid.mbtiles-null-tile.mbtiles'),
'prepare': path.join(__dirname, 'invalid.mbtiles-prepare.mbtiles')
'prepare': path.join(__dirname, 'invalid.mbtiles-prepare.mbtiles'),
'duplicate_layers': path.join(__dirname, 'invalid.mbtiles-duplicate-layers.mbtiles')
}
}
};
Binary file not shown.
9 changes: 9 additions & 0 deletions test/validators.mbtiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,12 @@ test('lib.validators.mbtiles: metadata fillzoom below tiles', function(t) {
t.end();
});
});

test('lib.validators.mbtiles: duplicate layers not allowed', function(t) {
validate(fixtures.invalid.mbtiles.duplicate_layers, function(err) {
t.ok(err, 'expected error');
t.equal(err.code, 'EINVALID', 'expected error code');
t.equal(err.message, expected.mbtilesErrors.duplicate_layers, 'expected error message');
t.end();
});
});

0 comments on commit 007e958

Please sign in to comment.