Ignore:
Timestamp:
2023-08-22T20:05:49+02:00 (13 months ago)
Author:
taylor.smock
Message:

Fix #22652: Stop parsing gpx files when wpt elements do not have valid coordinates

This does move the parsing code out of GpxReader into GpxParser and refactors it
so that it is (hopefully) easier to understand and debug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/GpxReaderTest.java

    r18801 r18817  
    55import static org.junit.jupiter.api.Assertions.assertThrows;
    66import static org.junit.jupiter.api.Assertions.assertTrue;
     7import static org.junit.jupiter.api.Assertions.fail;
    78
    89import java.io.ByteArrayInputStream;
     
    1415import java.util.Map;
    1516
     17import org.junit.jupiter.params.ParameterizedTest;
     18import org.junit.jupiter.params.provider.ValueSource;
    1619import org.openstreetmap.josm.TestUtils;
    1720import org.openstreetmap.josm.data.Bounds;
     
    8285    /**
    8386     * Tests invalid data.
    84      * @throws Exception always SAXException
    8587     */
    8688    @Test
    87     void testException() throws Exception {
     89    void testException() {
    8890        assertThrows(SAXException.class,
    8991                () -> new GpxReader(new ByteArrayInputStream("--foo--bar--".getBytes(StandardCharsets.UTF_8))).parse(true));
     
    100102                GpxReaderTest.parseGpxData(TestUtils.getRegressionDataFile(15634, "drumlish.gpx")).getMetaBounds());
    101103    }
     104
     105    @ParameterizedTest
     106    @ValueSource(strings = {
     107            "<gpx><wpt></wpt></gpx>",
     108    })
     109    void testIncompleteLocations(String gpx) {
     110        SAXException saxException = assertThrows(SAXException.class,
     111                () -> new GpxReader(new ByteArrayInputStream(gpx.getBytes(StandardCharsets.UTF_8))).parse(true));
     112        final String type;
     113        if ("<wpt>".regionMatches(0, gpx, 5, 4)) {
     114            type = "wpt";
     115        } else {
     116            fail("You need to add code to tell us what the exception for \"" + gpx + "\" should be");
     117            type = null;
     118        }
     119        assertEquals(type + " element does not have valid latitude and/or longitude.", saxException.getMessage());
     120    }
    102121}
Note: See TracChangeset for help on using the changeset viewer.