mapbox / mapbox/togeojson

Better handle XML parsing issues

Open
#150 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.3k
Forks
322
PR merge metrics
No merged PRs in 30d

Description

### Repro

```
const xml = new DOMParser().parseFromString('', 'text/xml');
try {
const geojson = togeojson(xml);
console.log(geojson);
} catch (err) {
console.error(err)
}
```

### Actual result

```
{ type: 'FeatureCollection', features: [] }
```

### Expected result

Exception thrown with error speaking to the fact that the XML is bad.

### Ideas for solution

```
var d = new DOMParser().parseFromString('bar', 'text/xml');
Array.from(d.querySelectorAll('parsererror > div')).forEach(err => console.log(err.innerText));
```

Outputs: `error on line 1 at column 19: Opening and ending tag mismatch: foo line 0 and foop`

Contributor guide

Open the contributing guide

Research direction

Start at the togeojson(xml) entry point and inspect how the DOMParser result exposes parsererror elements. Handle malformed XML so the conversion reports an exception containing the parser error, then verify it with the malformed XML repro and the expected thrown-error behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.