Changeset 19646 in josm


Ignore:
Timestamp:
2026-10-09T18:21:45+02:00 (2 hours ago)
Author:
gaben
Message:

see #24927 - report non-OSM JSON (e.g. GeoJSON from Postpass) as illegal data instead of crashing

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmJsonReader.java

    r19535 r19646  
    6565
    6666    private void parseRoot(JsonObject object) throws IllegalDataException {
    67         parseVersion(object.get("version").toString());
     67        JsonValue version = object.get("version");
     68        parseVersion(version != null ? version.toString() : null);
    6869        parseDownloadPolicy("download", object.getString("download", null));
    6970        parseUploadPolicy("upload", object.getString("upload", null));
  • trunk/test/unit/org/openstreetmap/josm/io/OsmJsonReaderTest.java

    r18816 r19646  
    260260    }
    261261
     262    /**
     263     * Non-regression test for ticket #24927. GeoJSON served as {@code application/json} (e.g. by Postpass)
     264     * must be reported as illegal data, not crash the reader.
     265     */
     266    @Test
     267    void testTicket24927() {
     268        byte[] geoJson = ("{\"type\": \"FeatureCollection\", \"features\": [{\"type\": \"Feature\", " +
     269                "\"geometry\": {\"type\": \"Point\", \"coordinates\": [10.1, 20.2]}, " +
     270                "\"properties\": {\"tags\": {\"fixme\": \"yes\"}}}]}").getBytes(StandardCharsets.UTF_8);
     271        IllegalDataException exception = assertThrows(IllegalDataException.class,
     272                () -> OsmJsonReader.parseDataSet(new ByteArrayInputStream(geoJson), NullProgressMonitor.INSTANCE));
     273        assertEquals("Missing mandatory attribute 'version'.", exception.getMessage());
     274    }
     275
    262276    static Stream<Arguments> testException() {
    263277        final byte[] smallJson = "{\"type\", \"node\", \"id\": 1, \"lat\": 1.0, \"lon\": 2.0}".getBytes(StandardCharsets.UTF_8);
Note: See TracChangeset for help on using the changeset viewer.