@@ -263,6 +263,25 @@ test('Value message with only an unknown field throws rather than looping', () =
263263 assert . throws ( ( ) => new VectorTile ( new Protobuf ( buf ) ) , / u n k n o w n f e a t u r e v a l u e / ) ;
264264} ) ;
265265
266+ test ( 'throws a clear error for a feature with no geometry (issue #39)' , ( ) => {
267+ const pbf = new Protobuf ( ) ;
268+ pbf . writeMessage ( 3 , ( _ , p ) => {
269+ p . writeStringField ( 1 , 'layer' ) ;
270+ p . writeMessage ( 2 , ( _ , p ) => {
271+ p . writeVarintField ( 1 , 1 ) ;
272+ p . writeVarintField ( 3 , 1 ) ;
273+ // intentionally no geometry field
274+ } , null ) ;
275+ p . writeVarintField ( 5 , 4096 ) ;
276+ } , null ) ;
277+
278+ const tile = new VectorTile ( new Protobuf ( pbf . finish ( ) ) ) ;
279+ const feature = tile . layers . layer . feature ( 0 ) ;
280+ assert . throws ( ( ) => feature . loadGeometry ( ) , / f e a t u r e h a s n o g e o m e t r y / ) ;
281+ assert . throws ( ( ) => feature . bbox ( ) , / f e a t u r e h a s n o g e o m e t r y / ) ;
282+ assert . throws ( ( ) => feature . toGeoJSON ( 0 , 0 , 0 ) , / f e a t u r e h a s n o g e o m e t r y / ) ;
283+ } ) ;
284+
266285test ( 'does not mutate prototypes via a "__proto__" layer name or property key' , ( ) => {
267286 // Hand-build a minimal MVT tile containing a layer named "__proto__"
268287 // with one feature whose properties include a "__proto__" key.
0 commit comments