diff --git a/Passepartout/App/iOS/CHANGELOG.md b/Passepartout/App/iOS/CHANGELOG.md index 16226587..a470b737 100644 --- a/Passepartout/App/iOS/CHANGELOG.md +++ b/Passepartout/App/iOS/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Release app in the open via GitHub Actions. +### Fixed + +- Trim whitespaces in text fields. + ## 1.17.2 (2021-11-30) ### Changed diff --git a/Passepartout/App/iOS/Scenes/NetworkSettingsViewController.swift b/Passepartout/App/iOS/Scenes/NetworkSettingsViewController.swift index a079aeb3..9dd4705d 100644 --- a/Passepartout/App/iOS/Scenes/NetworkSettingsViewController.swift +++ b/Passepartout/App/iOS/Scenes/NetworkSettingsViewController.swift @@ -250,18 +250,15 @@ class NetworkSettingsViewController: UITableViewController { // DNS: servers, domains // Proxy: address, port, PAC, bypass domains - let text = field.text ?? "" + let text = field.text?.stripped ?? "" if field.tag == FieldTag.dnsCustom.rawValue { switch networkSettings.dnsProtocol { case .https: - guard let string = field.text, let url = URL(string: string) else { - break - } - networkSettings.dnsHTTPSURL = url + networkSettings.dnsHTTPSURL = URL(string: text) case .tls: - networkSettings.dnsTLSServerName = field.text + networkSettings.dnsTLSServerName = text default: break @@ -281,11 +278,11 @@ class NetworkSettingsViewController: UITableViewController { networkSettings.dnsSearchDomains = [text] } } else if field.tag == FieldTag.proxyAddress.rawValue { - networkSettings.proxyAddress = field.text + networkSettings.proxyAddress = text } else if field.tag == FieldTag.proxyPort.rawValue { - networkSettings.proxyPort = UInt16(field.text ?? "0") + networkSettings.proxyPort = UInt16(text) ?? 0 } else if field.tag == FieldTag.proxyAutoConfigurationURL.rawValue { - if let string = field.text { + if let string = text { networkSettings.proxyAutoConfigurationURL = URL(string: string) } else { networkSettings.proxyAutoConfigurationURL = nil diff --git a/Passepartout/App/iOS/Scenes/Organizer/WizardHostViewController.swift b/Passepartout/App/iOS/Scenes/Organizer/WizardHostViewController.swift index efafc839..562f3551 100644 --- a/Passepartout/App/iOS/Scenes/Organizer/WizardHostViewController.swift +++ b/Passepartout/App/iOS/Scenes/Organizer/WizardHostViewController.swift @@ -95,7 +95,7 @@ class WizardHostViewController: UITableViewController, StrongTableHost { } @IBAction private func next() { - guard let enteredTitle = cellTitle?.field.text?.trimmingCharacters(in: .whitespaces), !enteredTitle.isEmpty else { + guard let enteredTitle = cellTitle?.field.text?.stripped, !enteredTitle.isEmpty else { return } guard let result = parsingResult else { diff --git a/Passepartout/App/iOS/Scenes/ServiceViewController.swift b/Passepartout/App/iOS/Scenes/ServiceViewController.swift index aa14df0e..0c4ea970 100644 --- a/Passepartout/App/iOS/Scenes/ServiceViewController.swift +++ b/Passepartout/App/iOS/Scenes/ServiceViewController.swift @@ -449,10 +449,11 @@ class ServiceViewController: UIViewController, StrongTableHost { } alert.addCancelAction(L10n.Global.cancel) alert.addPreferredAction(L10n.Service.Cells.TrustedAddWifi.caption) { - guard let wifi = alert.textFields?.first?.text else { + let ssid = alert.textFields?.first?.text?.stripped + guard let ssid = ssid, !ssid.isEmpty else { return } - self.trustedNetworks.addWifi(wifi) + self.trustedNetworks.addWifi(ssid) } present(alert, animated: true, completion: nil) } diff --git a/Passepartout/App/macOS/CHANGELOG.md b/Passepartout/App/macOS/CHANGELOG.md index 5c86ea07..bcf407cc 100644 --- a/Passepartout/App/macOS/CHANGELOG.md +++ b/Passepartout/App/macOS/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Last update was not refreshed on "Refresh infrastructure". +- Trim whitespaces in text fields. ## 1.17.2 (2021-11-30) diff --git a/Passepartout/App/macOS/Scenes/Service/Customization/DNSViewController.swift b/Passepartout/App/macOS/Scenes/Service/Customization/DNSViewController.swift index 309a5f89..aaa37604 100644 --- a/Passepartout/App/macOS/Scenes/Service/Customization/DNSViewController.swift +++ b/Passepartout/App/macOS/Scenes/Service/Customization/DNSViewController.swift @@ -158,7 +158,7 @@ class DNSViewController: NSViewController, ProfileCustomization { networkSettings.dnsHTTPSURL = URL(string: textDNSCustom.stringValue) case .tls: - networkSettings.dnsTLSServerName = textDNSCustom.stringValue + networkSettings.dnsTLSServerName = textDNSCustom.stringValue.stripped default: break diff --git a/Passepartout/App/macOS/Scenes/Service/Customization/ProxyViewController.swift b/Passepartout/App/macOS/Scenes/Service/Customization/ProxyViewController.swift index c794890e..be7bc2dc 100644 --- a/Passepartout/App/macOS/Scenes/Service/Customization/ProxyViewController.swift +++ b/Passepartout/App/macOS/Scenes/Service/Customization/ProxyViewController.swift @@ -112,7 +112,7 @@ class ProxyViewController: NSViewController, ProfileCustomization { return } view.endEditing() - networkSettings.proxyAddress = textProxyAddress.stringValue + networkSettings.proxyAddress = textProxyAddress.stringValue.stripped networkSettings.proxyPort = UInt16(textProxyPort.stringValue) networkSettings.proxyAutoConfigurationURL = URL(string: textPAC.stringValue) networkSettings.proxyBypassDomains = tableProxyBypass.rows diff --git a/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksAddViewController.swift b/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksAddViewController.swift index a2f0d032..0a5fb6c2 100644 --- a/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksAddViewController.swift +++ b/Passepartout/App/macOS/Scenes/Service/Customization/TrustedNetworksAddViewController.swift @@ -49,7 +49,7 @@ class TrustedNetworksAddViewController: NSViewController { } @IBAction private func confirm(_ sender: Any?) { - let ssid = textSSID.stringValue.trimmingCharacters(in: .whitespaces) + let ssid = textSSID.stringValue.stripped guard !ssid.isEmpty else { return } diff --git a/Passepartout/App/macOS/Tables/TextTableView.swift b/Passepartout/App/macOS/Tables/TextTableView.swift index 3b8389da..4ddda689 100644 --- a/Passepartout/App/macOS/Tables/TextTableView.swift +++ b/Passepartout/App/macOS/Tables/TextTableView.swift @@ -143,7 +143,7 @@ extension TextTableView: NSTableViewDataSource, NSTableViewDelegate { rows.remove(at: row) return } - rows[row] = string + rows[row] = string.stripped } func tableViewSelectionDidChange(_ notification: Notification) { diff --git a/Passepartout/App/macOS/Tables/TextTableView.xib b/Passepartout/App/macOS/Tables/TextTableView.xib index 4545e3aa..2f42a6b5 100644 --- a/Passepartout/App/macOS/Tables/TextTableView.xib +++ b/Passepartout/App/macOS/Tables/TextTableView.xib @@ -1,8 +1,8 @@ - + - + @@ -14,7 +14,7 @@ - + @@ -22,21 +22,20 @@ - + - + - - + + - + - diff --git a/PassepartoutCore/Sources/PassepartoutCore/Model/Credentials.swift b/PassepartoutCore/Sources/PassepartoutCore/Model/Credentials.swift index f56a6adf..963c8b00 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Model/Credentials.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Model/Credentials.swift @@ -38,8 +38,8 @@ public extension Credentials { } func trimmed() -> Credentials { - let trimmedUsername = username.trimmingCharacters(in: .whitespacesAndNewlines) - let trimmedPassword = password.trimmingCharacters(in: .whitespacesAndNewlines) + let trimmedUsername = username.stripped + let trimmedPassword = password.stripped return Credentials(trimmedUsername, trimmedPassword) } } diff --git a/PassepartoutCore/Sources/PassepartoutCore/Utils.swift b/PassepartoutCore/Sources/PassepartoutCore/Utils.swift index 78b14178..b4cdc5f9 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Utils.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Utils.swift @@ -230,3 +230,9 @@ public extension Infrastructure.Metadata { return URL(string: string) } } + +public extension String { + var stripped: String { + return trimmingCharacters(in: .whitespacesAndNewlines) + } +}