tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
987 stars 223 forks source link

Check for GPX root node on parse #276

Closed derinwalters closed 5 months ago

derinwalters commented 6 months ago

Looks like the raising of GPXException inside the parse method uses a message about requiring a gpx root node, but it doesn't actually check for one. Instead, it is only checking for the existence of root. What this means in practice is that no errors are thrown if I load a different format's valid XML, for example a KML file.

I would like to propose that this line in parser.py be changed from:

        if root is None:
            raise mod_gpx.GPXException('Document must have a `gpx` root node.')

to:

        if root is None or root.tag.lower() != 'gpx':
            raise mod_gpx.GPXException('Document must have a `gpx` root node.')
tkrajina commented 5 months ago

Yes, you're right. Fixed it now (in dev). Thanks!