Skip to content

Commit d89d355

Browse files
elhoimclaude
andcommitted
fix: [wifi_geolocation_kml] declare the gx namespace on the KML root element
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 270a58c commit d89d355

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/sysdiagnose/analysers/wifi_geolocation_kml.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ def execute(self) -> str:
2525
@staticmethod
2626
def generate_kml_from_known_networks_json(json_data: dict) -> str:
2727
"""Generates KML XML string from known networks JSON data."""
28-
kml = ET.Element("kml", xmlns="http://www.opengis.net/kml/2.2")
28+
# the gx: prefix is used below (gx:Tour, gx:Playlist, gx:FlyTo, ...), so its namespace
29+
# has to be declared on the root element or the document is not namespace-well-formed
30+
kml = ET.Element(
31+
"kml",
32+
{
33+
"xmlns": "http://www.opengis.net/kml/2.2",
34+
"xmlns:gx": "http://www.google.com/kml/ext/2.2",
35+
},
36+
)
2937
document = ET.SubElement(kml, "Document")
3038

3139
# Add tour elements

tests/test_analysers_wifi_geolocation_kml.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import unittest
3+
import xml.etree.ElementTree as ET
34

45
from sysdiagnose.analysers.wifi_geolocation_kml import WifiGeolocationKmlAnalyser
56
from tests import SysdiagnoseTestCase
@@ -20,6 +21,23 @@ def test_analyse_wifi_geolocation_kml(self):
2021
self.assert_result_summary_consistent(a, a.get_result())
2122
# FIXME check for something else within the file...
2223

24+
def test_generated_kml_is_namespace_well_formed(self):
25+
"""The gx: prefix must be declared, otherwise no conforming XML parser can read the file."""
26+
kml = WifiGeolocationKmlAnalyser.generate_kml_from_known_networks_json(
27+
{
28+
"net1": {
29+
"SSID": "test-ssid",
30+
"AddedAt": "2023-05-24T13:29:15Z",
31+
"Latitude": 1.0,
32+
"Longitude": 2.0,
33+
}
34+
}
35+
)
36+
# on main this raises ParseError: unbound prefix
37+
root = ET.fromstring(kml)
38+
self.assertEqual("{http://www.opengis.net/kml/2.2}kml", root.tag)
39+
self.assertIn("http://www.google.com/kml/ext/2.2", kml)
40+
2341

2442
if __name__ == "__main__":
2543
unittest.main()

0 commit comments

Comments
 (0)