]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Ensure that all tunnel names are trimmed of whitespaces
authorRoopesh Chander <roop@roopc.net>
Sat, 3 Nov 2018 10:15:29 +0000 (15:45 +0530)
committerRoopesh Chander <roop@roopc.net>
Sat, 3 Nov 2018 10:15:29 +0000 (15:45 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/UI/TunnelViewModel.swift
WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift

index a9ee6f8274ac86515e45f94e066e18c5330a51d5..8a9cba49751a032fa19dc9fe7be1af5b66731683 100644 (file)
@@ -97,7 +97,7 @@ class TunnelViewModel {
 
         func save() -> SaveResult<InterfaceConfiguration> {
             fieldsWithError.removeAll()
-            guard let name = scratchpad[.name], (!name.isEmpty) else {
+            guard let name = scratchpad[.name]?.trimmingCharacters(in: .whitespacesAndNewlines), (!name.isEmpty) else {
                 fieldsWithError.insert(.name)
                 return .error("Interface name is required")
             }
index 9dd298a1f8bf6508028173a92b665523bef98399..929b6b027835ca37f340fc47221eaae340b96d1c 100644 (file)
@@ -116,7 +116,7 @@ class QRScanViewController: UIViewController {
         alert.addTextField(configurationHandler: nil)
         alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil))
         alert.addAction(UIAlertAction(title: NSLocalizedString("Save", comment: ""), style: .default, handler: { [weak self] _ in
-            let title = alert.textFields?[0].text ?? ""
+            let title = alert.textFields?[0].text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
             if (title.isEmpty) { return }
             tunnelConfiguration.interface.name = title
             if let s = self {
index e42b9642fdb6120fce5731ff803ac2b9cde5d5cf..df509a629369db9ce02729021434d2a2972faa6b 100644 (file)
@@ -179,7 +179,7 @@ class TunnelsListTableViewController: UIViewController {
     func importFromFile(url: URL) {
         // Import configurations from a .conf or a .zip file
         if (url.pathExtension == "conf") {
-            let fileBaseName = url.deletingPathExtension().lastPathComponent
+            let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
             if let fileContents = try? String(contentsOf: url),
                 let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
                 tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in
@@ -206,7 +206,8 @@ class TunnelsListTableViewController: UIViewController {
             }
             
             for (i, unarchivedFile) in unarchivedFiles.enumerated().reversed() {
-                if let trimmedName = URL(string: unarchivedFile.fileName)?.deletingPathExtension().lastPathComponent, !trimmedName.isEmpty {
+                let fileBaseName = URL(string: unarchivedFile.fileName)?.deletingPathExtension().lastPathComponent
+                if let trimmedName = fileBaseName?.trimmingCharacters(in: .whitespacesAndNewlines), !trimmedName.isEmpty {
                     unarchivedFiles[i].fileName = trimmedName
                 } else {
                     unarchivedFiles.remove(at: i)