gpxpy icon indicating copy to clipboard operation
gpxpy copied to clipboard

Links in XML not properly encoded

Open krzys-h opened this issue 6 months ago • 0 comments

I'm trying to alter a .gpx file which contains a link along the lines of:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1">
  <metadata>
    <link href="https://example.com/?this=is&amp;an=example">
      <text>some text</text>
    </link>
  </metadata>
</gpx>

After modifying the file using gpxpy and exporting with to_xml(), this turns into:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1">
  <metadata>
    <link href="https://example.com/?this=is&an=example">
      <text>some text</text>
    </link>
  </metadata>
</gpx>

which is not valid XML (as even the GitHub markdown highlighting shows) - unlike HTML5, you need to always encode the &amp;. This causes the file to fail to import in gpxpod (and maybe other gpx viewers as well)

krzys-h avatar Jul 27 '24 16:07 krzys-h