Blob Blame History Raw
From 24d842347a294fe19393f95c3ce98cc5de9bcabe Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 14 Mar 2019 01:22:39 +0100
Subject: [PATCH 1/3] tests: Add test for issue #6

---
 geocode-glib/tests/geocode-glib.c            | 1 +
 geocode-glib/tests/meson.build               | 1 +
 geocode-glib/tests/nominatim-place_rank.json | 1 +
 3 files changed, 3 insertions(+)
 create mode 100644 geocode-glib/tests/nominatim-place_rank.json

diff --git a/geocode-glib/tests/geocode-glib.c b/geocode-glib/tests/geocode-glib.c
index 5da23e5..e7d6d84 100644
--- a/geocode-glib/tests/geocode-glib.c
+++ b/geocode-glib/tests/geocode-glib.c
@@ -789,6 +789,7 @@ test_resolve_json (void)
 		{ "nominatim-area.json", 1, NULL, "area", "Guildford Park" },
 		{ "nominatim-no-results.json", 1, "No matches found for request", NULL, NULL },
 		{ "nominatim-data-type-change.json", 12, NULL, "osm_id", "335673748" },
+		{ "nominatim-place_rank.json", 10, NULL, "osm_id", "2555133" },
 	};
 
 	for (i = 0; i < G_N_ELEMENTS (tests); i++) {
diff --git a/geocode-glib/tests/meson.build b/geocode-glib/tests/meson.build
index 61df92c..59a065c 100644
--- a/geocode-glib/tests/meson.build
+++ b/geocode-glib/tests/meson.build
@@ -28,6 +28,7 @@ install_data('locale_format.json',
              'locale_name.json',
              'nominatim-area.json',
              'nominatim-no-results.json',
+             'nominatim-place_rank.json',
              'nominatim-rio.json',
              'osm_type0.json',
              'osm_type1.json',
diff --git a/geocode-glib/tests/nominatim-place_rank.json b/geocode-glib/tests/nominatim-place_rank.json
new file mode 100644
index 0000000..bb5f008
--- /dev/null
+++ b/geocode-glib/tests/nominatim-place_rank.json
@@ -0,0 +1 @@
+[{"place_id":"159575959","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"relation","osm_id":"2555133","boundingbox":["55.4913076","55.9574097","37.290502","37.9674277"],"lat":"55.7506828","lon":"37.6174976","display_name":"Moskva, Центральный административный округ, Moskva, Centrální federální okruh, Ruská federace","category":"place","type":"city","importance":0.81231629038453,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_city.p.20.png","address":{"city":"Moskva","state_district":"Центральный административный округ","state":"Moskva","country":"Ruská federace","country_code":"ru"}},{"place_id":"159148837","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"relation","osm_id":"102269","boundingbox":["55.1421745","56.0212238","36.8031012","37.9674277"],"lat":"55.4792046","lon":"37.3273304","display_name":"Moskva, Centrální federální okruh, Ruská federace","category":"boundary","type":"administrative","importance":0.81231629038453,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_boundary_administrative.p.20.png","address":{"state":"Moskva","country":"Ruská federace","country_code":"ru"}},{"place_id":"158661492","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"relation","osm_id":"121430","boundingbox":["46.710912","46.758882","-117.0396979","-116.9620679"],"lat":"46.7323875","lon":"-117.000165","display_name":"Moscow, Latah County, Idaho, Spojené státy americké","category":"place","type":"city","importance":0.53629964602682,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_city.p.20.png","address":{"city":"Moscow","county":"Latah County","state":"Idaho","country":"Spojené státy americké","country_code":"us"}},{"place_id":"83209933","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"87186419","boundingbox":["25.2302669","25.2325261","55.1643501","55.1667109"],"lat":"25.2313998","lon":"55.1655538746233","display_name":"Moscow, Dubaj, دبي‎, Spojené arabské emiráty","category":"place","type":"island","importance":0.425,"address":{"island":"Moscow","city":"Dubaj","state":"دبي‎","country":"Spojené arabské emiráty","country_code":"ae"}},{"place_id":"158830575","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"relation","osm_id":"188588","boundingbox":["41.332327","41.359539","-75.5571869","-75.5055579"],"lat":"41.3367497","lon":"-75.518519","display_name":"Moscow, Lackawanna County, Pensylvánie, Spojené státy americké","category":"boundary","type":"administrative","importance":0.40496966945241,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_boundary_administrative.p.20.png","address":{"city":"Moscow","county":"Lackawanna County","state":"Pensylvánie","country":"Spojené státy americké","country_code":"us"}},{"place_id":"453497","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"157606151","boundingbox":["39.5237014","39.5637014","-79.0250272","-78.9850272"],"lat":"39.5437014","lon":"-79.0050272","display_name":"Moscow, Allegany County, Maryland, Spojené státy americké","category":"place","type":"hamlet","importance":0.37594331946278,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_village.p.20.png","address":{"hamlet":"Moscow","county":"Allegany County","state":"Maryland","country":"Spojené státy americké","country_code":"us"}},{"place_id":"421984","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"153805006","boundingbox":["37.3914401","37.4314401","-89.0725736","-89.0325736"],"lat":"37.4114401","lon":"-89.0525736","display_name":"Moscow, Union County, Illinois, Spojené státy americké","category":"place","type":"hamlet","importance":0.375,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_village.p.20.png","address":{"hamlet":"Moscow","county":"Union County","state":"Illinois","country":"Spojené státy americké","country_code":"us"}},{"place_id":"436343","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"154194549","boundingbox":["42.0302346","42.0702346","-84.5298798","-84.4898798"],"lat":"42.0502346","lon":"-84.5098798","display_name":"Moscow, Hillsdale County, Michigan, Spojené státy americké","category":"place","type":"village","importance":0.375,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_village.p.20.png","address":{"village":"Moscow","county":"Hillsdale County","state":"Michigan","country":"Spojené státy americké","country_code":"us"}},{"place_id":"390992","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"151964024","boundingbox":["43.6871833","43.7271833","-93.1182537","-93.0782537"],"lat":"43.7071833","lon":"-93.0982537","display_name":"Moscow, Freeborn County, Minnesota, Spojené státy americké","category":"place","type":"village","importance":0.375,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_village.p.20.png","address":{"village":"Moscow","county":"Freeborn County","state":"Minnesota","country":"Spojené státy americké","country_code":"us"}},{"place_id":"377384","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"151724752","boundingbox":["39.1463923","39.1863923","-94.5618989","-94.5218989"],"lat":"39.1663923","lon":"-94.5418989","display_name":"Moscow, Clay County, Missouri, Spojené státy americké","category":"place","type":"hamlet","importance":0.375,"icon":"https:\/\/nominatim.openstreetmap.org\/images\/mapicons\/poi_place_village.p.20.png","address":{"hamlet":"Moscow","county":"Clay County","state":"Missouri","country":"Spojené státy americké","country_code":"us"}}]
-- 
2.26.0


From e7216583a219df9d9eba21a7fe1b74543b6d5851 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 14 Mar 2019 01:23:19 +0100
Subject: [PATCH 2/3] geocode-nominatim: Fix possible crash with missing
 place_rank

Spotted by Ordissimo <thierry@ordissimo.com>

Closes: #6
---
 geocode-glib/geocode-nominatim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/geocode-glib/geocode-nominatim.c b/geocode-glib/geocode-nominatim.c
index b2abc97..fc333dc 100644
--- a/geocode-glib/geocode-nominatim.c
+++ b/geocode-glib/geocode-nominatim.c
@@ -390,9 +390,11 @@ get_place_type_from_attributes (GHashTable *ht)
                 place_type =  GEOCODE_PLACE_TYPE_DRAINAGE;
         } else if (g_strcmp0 (category, "boundary") == 0) {
                 if (g_strcmp0 (type, "administrative") == 0) {
+                        const char *place_rank;
                         int rank;
 
-                        rank = atoi (g_hash_table_lookup (ht, "place_rank"));
+                        place_rank = g_hash_table_lookup (ht, "place_rank");
+                        rank = place_rank ? atoi (place_rank) : 0;
                         if (rank < 2)
                                 place_type =  GEOCODE_PLACE_TYPE_UNKNOWN;
 
-- 
2.26.0


From 0d4f1bad55121dd70f38f68d64ea7d755634ebf1 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 14 Mar 2019 01:24:13 +0100
Subject: [PATCH 3/3] tests: Fix missing installed-tests file

---
 geocode-glib/tests/meson.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/geocode-glib/tests/meson.build b/geocode-glib/tests/meson.build
index 59a065c..a64baaa 100644
--- a/geocode-glib/tests/meson.build
+++ b/geocode-glib/tests/meson.build
@@ -27,6 +27,7 @@ test('Test mock backend', e)
 install_data('locale_format.json',
              'locale_name.json',
              'nominatim-area.json',
+             'nominatim-data-type-change.json',
              'nominatim-no-results.json',
              'nominatim-place_rank.json',
              'nominatim-rio.json',
-- 
2.26.0