diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-07-12 10:22:32 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-07-12 14:27:57 +0200 |
| commit | 2aeb6c152ee080a23a66e35a8933f6d8fb4768bc (patch) | |
| tree | 0de4abed14ce543e669d05976d989e0d834a1d55 /ios | |
| parent | a127de75e33af3bfc42e9e8bf049cb4447430223 (diff) | |
| download | mullvadvpn-2aeb6c152ee080a23a66e35a8933f6d8fb4768bc.tar.xz mullvadvpn-2aeb6c152ee080a23a66e35a8933f6d8fb4768bc.zip | |
Make geojson loader safer
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN/ConnectViewController.swift | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ios/MullvadVPN/ConnectViewController.swift b/ios/MullvadVPN/ConnectViewController.swift index 8673f8a23b..44475e603b 100644 --- a/ios/MullvadVPN/ConnectViewController.swift +++ b/ios/MullvadVPN/ConnectViewController.swift @@ -24,6 +24,8 @@ protocol ConnectViewControllerDelegate: AnyObject { class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainment, TunnelObserver { + private static let geoJSONSourceFileName = "countries.geo.json" + weak var delegate: ConnectViewControllerDelegate? let notificationController = NotificationController() @@ -438,11 +440,22 @@ class ConnectViewController: UIViewController, MKMapViewDelegate, RootContainmen } private func loadGeoJSONData() { - let fileURL = Bundle.main.url(forResource: "countries.geo", withExtension: "json")! - let data = try! Data(contentsOf: fileURL) + guard let fileURL = Bundle.main.url( + forResource: Self.geoJSONSourceFileName, + withExtension: nil + ) else { + logger.debug("Failed to locate \(Self.geoJSONSourceFileName) in main bundle.") + return + } - let overlays = try! GeoJSON.decodeGeoJSON(data) - mainContentView.mapView.addOverlays(overlays, level: .aboveLabels) + do { + let data = try Data(contentsOf: fileURL) + let overlays = try GeoJSON.decodeGeoJSON(data) + + mainContentView.mapView.addOverlays(overlays) + } catch { + logger.error(chainedError: AnyChainedError(error), message: "Failed to load geojson.") + } } } |
