Changeset 18819 in josm for trunk


Ignore:
Timestamp:
2023-08-23T13:53:32+02:00 (11 months ago)
Author:
taylor.smock
Message:

See #22652, r18817: Stop parsing gpx files when point elements have invalid coordinates

This adds back the wpt check that was temporarily removed in r18818 to get back
to the previous "known good" state and additionally adds checks for rtept and
trkpt elements.

This also removes a change to build.xml that was accidentally committed in r18818.
The specific change (adding Automatic-Module-Name to the JOSM manifest) will
probably be done in a separate commit in the future.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r18818 r18819  
    188188                <!-- Indicate that this jar may have version specific classes. Only used in Java9+. -->
    189189                <attribute name="Multi-Release" value="true"/>
    190                 <attribute name="Automatic-Module-Name" value="org.openstreetmap.josm"/>
    191190            </manifest>
    192191        </jar>
  • trunk/src/org/openstreetmap/josm/io/GpxParser.java

    r18818 r18819  
    638638                currentState = states.pop();
    639639                convertUrlToLink(currentWayPoint.attr);
     640                if (!currentWayPoint.isLatLonKnown()) {
     641                    throw new SAXException(tr("{0} element does not have valid latitude and/or longitude.", localName));
     642                }
    640643                currentRoute.routePoints.add(currentWayPoint);
    641644                break;
     
    643646                currentState = states.pop();
    644647                convertUrlToLink(currentWayPoint.attr);
     648                if (!currentWayPoint.isLatLonKnown()) {
     649                    throw new SAXException(tr("{0} element does not have valid latitude and/or longitude.", localName));
     650                }
    645651                currentTrackSeg.add(currentWayPoint);
    646652                break;
     
    649655                convertUrlToLink(currentWayPoint.attr);
    650656                currentWayPoint.getExtensions().addAll(currentExtensionCollection);
     657                if (!currentWayPoint.isLatLonKnown()) {
     658                    currentExtensionCollection.clear();
     659                    throw new SAXException(tr("{0} element does not have valid latitude and/or longitude.", localName));
     660                }
    651661                data.waypoints.add(currentWayPoint);
    652662                currentExtensionCollection.clear();
  • trunk/test/unit/org/openstreetmap/josm/io/GpxReaderTest.java

    r18818 r18819  
    104104
    105105    @ParameterizedTest
    106     @ValueSource(strings = "<gpx><wpt></wpt></gpx>")
     106    @ValueSource(strings = {
     107            "<gpx><wpt></wpt></gpx>",
     108            "<gpx><trk><trkseg><trkpt></trkpt></trkseg></trk></gpx>",
     109            "<gpx><rte><rtept></rtept></rte></gpx>"
     110    })
    107111    void testIncompleteLocations(String gpx) {
    108112        SAXException saxException = assertThrows(SAXException.class,
     
    111115        if ("<wpt>".regionMatches(0, gpx, 5, 4)) {
    112116            type = "wpt";
     117        } else if ("<trkpt>".regionMatches(0, gpx, 18, 7)) {
     118            type = "trkpt";
     119        } else if ("<rtept>".regionMatches(0, gpx, 10, 7)) {
     120            type = "rtept";
    113121        } else {
    114122            fail("You need to add code to tell us what the exception for \"" + gpx + "\" should be");
Note: See TracChangeset for help on using the changeset viewer.