From 2b3347b2948af7f99e67bd50300f48b5ffb442cd Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 6 Nov 2018 22:32:10 +0530 Subject: [PATCH] Importing: Error out on file with unsupported file extension --- .../UI/iOS/TunnelsListTableViewController.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index 7e06bce..bd067c8 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -240,6 +240,8 @@ class TunnelsListTableViewController: UIViewController { self?.showErrorAlert(title: "Created \(numberSuccessful) tunnels", message: "Created \(numberSuccessful) of \(unarchivedFiles.count) tunnels from zip archive") } + } else { + fatalError("Unsupported file extension") } } } @@ -249,7 +251,13 @@ class TunnelsListTableViewController: UIViewController { extension TunnelsListTableViewController: UIDocumentPickerDelegate { func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { if let url = urls.first { - importFromFile(url: url) + if (url.pathExtension == "conf" || url.pathExtension == "zip") { + importFromFile(url: url) + } else { + // What if a file provider extension didn't respect our 'documentTypes' parameter + self.showErrorAlert(title: "Invalid file extension", + message: "Please select a WireGuard configuration file (.conf) or a zip archive (.zip) for importing") + } } } }