Skip to content

Commit

Permalink
jsontogeojson: Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Nov 25, 2022
1 parent e01cab4 commit d48b989
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcoveofds/geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _dereference_object(self, ref, list):

if "id" in ref:
for item in list:
if item.get("id") == ref["id"]:
if isinstance(item, dict) and item.get("id") == ref["id"]:
return item

return ref
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/json_to_geojson/dont_crash_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"networks": [
{
"id": "a096d627-72e1-4f9b-b129-951b1737bff4",
"name": "Ghana Fibre Network",
"organisations": [
"my mate down the pub"
],
"phases": [
{
"funders": [
{"id": "1"}
]
}
],
"links": [
{
"rel": "describedby",
"href": "https://raw.githubusercontent.com/Open-Telecoms-Data/open-fibre-data-standard/0__1__0__beta/schema/network-schema.json"
}
]
}
]
}
17 changes: 17 additions & 0 deletions tests/test_json_to_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,20 @@ def test_json_to_geojson(filename):
with open(meta_expected_filename) as fp:
meta_expected_data = json.load(fp)
assert meta_expected_data == converter.get_meta_json()


def test_dont_crash_1():
"""Just put as much bad stuff as possible in the input and make sure it doesn't crash!
We don't care about testing output. Other tests can do that."""
json_filename = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"fixtures",
"json_to_geojson",
"dont_crash_1.json",
)

with open(json_filename) as fp:
json_data = json.load(fp)

converter = JSONToGeoJSONConverter()
converter.process_package(json_data)

0 comments on commit d48b989

Please sign in to comment.