Changeset 15865 in josm


Ignore:
Timestamp:
2020-02-16T22:29:06+01:00 (5 months ago)
Author:
Don-vip
Message:

fix #18722 - exclude json file extension from GeoJsonImporter + add robustness

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/GeoJSONImporter.java

    r15588 r15865  
    3333
    3434    private static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions(
    35         "geojson,json", "geojson", tr("GeoJSON file") + " (*.geojson, *.geojson.gz, *.geojson.bz2, *.geojson.xz, *.geojson.zip, *.json)",
     35        "geojson", "geojson", tr("GeoJSON file") + " (*.geojson, *.geojson.gz, *.geojson.bz2, *.geojson.xz, *.geojson.zip)",
    3636        ExtensionFileFilter.AddArchiveExtension.NONE, Arrays.asList("gz", "bz", "bz2", "xz", "zip"));
    3737
  • trunk/src/org/openstreetmap/josm/io/GeoJSONReader.java

    r15785 r15865  
    7474    private void parseRoot(final JsonObject object) throws IllegalDataException {
    7575        parseCrs(object.getJsonObject(CRS));
    76         switch (object.getString(TYPE)) {
     76        switch (Optional.ofNullable(object.getJsonString(TYPE))
     77                .orElseThrow(() -> new IllegalDataException("No type")).getString()) {
    7778            case "FeatureCollection":
    7879                parseFeatureCollection(object.getJsonArray(FEATURES));
  • trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java

    r15736 r15865  
    77import static org.junit.Assert.assertTrue;
    88
     9import java.io.ByteArrayInputStream;
    910import java.io.InputStream;
     11import java.nio.charset.StandardCharsets;
    1012import java.nio.file.Files;
    1113import java.nio.file.Paths;
     
    133135    }
    134136
     137    /**
     138     * Test reading a JSON file which is not a proper GeoJSON (type missing).
     139     * @throws IllegalDataException always
     140     */
     141    @Test(expected = IllegalDataException.class)
     142    public void testReadGeoJsonWithoutType() throws IllegalDataException {
     143        new GeoJSONReader().doParseDataSet(new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)), null);
     144    }
     145
    135146    private static boolean areEqualNodes(final OsmPrimitive p1, final OsmPrimitive p2) {
    136147        return (p1 instanceof Node)
Note: See TracChangeset for help on using the changeset viewer.