aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-03 15:45:29 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-03 15:45:29 +0530
commit366ca7802af8f1f77f41ecf91fd32f8bf3cee082 (patch)
tree2cf1145e499842dc37097d0c8710beee5126e8b6
parentZip archive: Handle files within folders inside the zip (diff)
downloadwireguard-apple-366ca7802af8f1f77f41ecf91fd32f8bf3cee082.tar.xz
wireguard-apple-366ca7802af8f1f77f41ecf91fd32f8bf3cee082.zip
Ensure that all tunnel names are trimmed of whitespaces
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift2
-rw-r--r--WireGuard/WireGuard/UI/iOS/QRScanViewController.swift2
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift5
3 files changed, 5 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index a9ee6f8..8a9cba4 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -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")
}
diff --git a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
index 9dd298a..929b6b0 100644
--- a/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/QRScanViewController.swift
@@ -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 {
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index e42b964..df509a6 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -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)