]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
importer: Validate country codes from Geofeeds
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Sep 2022 08:49:56 +0000 (08:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 27 Sep 2022 16:47:17 +0000 (16:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/location-importer.in

index d0384b5b6781ba27c8bd9ba2855abb661bc2811e..d8f9cbfb5e286ebca56d81536bca2d3d66974a68 100644 (file)
@@ -1421,7 +1421,15 @@ class CLI(object):
                                                        log.debug("Could not parse network: %s" % network)
                                                        continue
 
-                                               # XXX Check the country code
+                                               # Strip any excess whitespace from country codes
+                                               if country:
+                                                       country = country.strip()
+
+                                               # Check the country code
+                                               if not location.country_code_is_valid(country):
+                                                       log.warning("Invalid country code in Geofeed %s: %s" \
+                                                               % (geofeed.url, country))
+                                                       continue
 
                                                # Write this into the database
                                                self.db.execute("""