mapbox / mapbox/mapbox-gl-js

Validate GeoJSON

Open
#5,134 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 0.39.1

Due to some sloppy code I passed some pretty defective GeoJSON, like:

```
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"coordinates": [145, -37]
}
]
}
```

Instead of raising a " Error: Input data is not a valid GeoJSON object." error, this error is thrown:

```
Error: TypeError: Cannot read property 'type' of undefined
at Actor.receive (mapbox-gl.js:397)
at e.whenMapLoaded ((index):58)
at e.Evented.fire (mapbox-gl.js:417)
at e._render (mapbox-gl.js:391)
```

Adding at least a `"geometry"` attribute to the `Feature` object triggers the correct error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the malformed FeatureCollection in the issue and follow the reported stack trace to Actor.receive in the mapbox-gl.js bundle. Confirm that a Feature missing geometry produces the intended invalid GeoJSON error rather than a TypeError; the issue is done when this case is handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.