Ensure that all tunnel names are trimmed of whitespaces
This commit is contained in:
parent
eb122f87e2
commit
4ab4c79934
|
@ -97,7 +97,7 @@ class TunnelViewModel {
|
||||||
|
|
||||||
func save() -> SaveResult<InterfaceConfiguration> {
|
func save() -> SaveResult<InterfaceConfiguration> {
|
||||||
fieldsWithError.removeAll()
|
fieldsWithError.removeAll()
|
||||||
guard let name = scratchpad[.name], (!name.isEmpty) else {
|
guard let name = scratchpad[.name]?.trimmingCharacters(in: .whitespacesAndNewlines), (!name.isEmpty) else {
|
||||||
fieldsWithError.insert(.name)
|
fieldsWithError.insert(.name)
|
||||||
return .error("Interface name is required")
|
return .error("Interface name is required")
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ class QRScanViewController: UIViewController {
|
||||||
alert.addTextField(configurationHandler: nil)
|
alert.addTextField(configurationHandler: nil)
|
||||||
alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: 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
|
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 }
|
if (title.isEmpty) { return }
|
||||||
tunnelConfiguration.interface.name = title
|
tunnelConfiguration.interface.name = title
|
||||||
if let s = self {
|
if let s = self {
|
||||||
|
|
|
@ -179,7 +179,7 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
func importFromFile(url: URL) {
|
func importFromFile(url: URL) {
|
||||||
// Import configurations from a .conf or a .zip file
|
// Import configurations from a .conf or a .zip file
|
||||||
if (url.pathExtension == "conf") {
|
if (url.pathExtension == "conf") {
|
||||||
let fileBaseName = url.deletingPathExtension().lastPathComponent
|
let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
if let fileContents = try? String(contentsOf: url),
|
if let fileContents = try? String(contentsOf: url),
|
||||||
let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
|
let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
|
||||||
tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in
|
tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in
|
||||||
|
@ -206,7 +206,8 @@ class TunnelsListTableViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, unarchivedFile) in unarchivedFiles.enumerated().reversed() {
|
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
|
unarchivedFiles[i].fileName = trimmedName
|
||||||
} else {
|
} else {
|
||||||
unarchivedFiles.remove(at: i)
|
unarchivedFiles.remove(at: i)
|
||||||
|
|
Loading…
Reference in New Issue