diff --git a/WordPressAuthenticator/Model/LoginFields+Validation.swift b/WordPressAuthenticator/Model/LoginFields+Validation.swift index 2c5d2576a..33cd2c4db 100644 --- a/WordPressAuthenticator/Model/LoginFields+Validation.swift +++ b/WordPressAuthenticator/Model/LoginFields+Validation.swift @@ -14,7 +14,11 @@ extension LoginFields { /// Returns *true* if the siteURL contains a valid URL. False otherwise. /// func validateSiteForSignin() -> Bool { - return siteAddress.isValidURL() + guard let url = URL(string: NSURL.idnEncodedURL(siteAddress)) else { + return false + } + + return !url.absoluteString.isEmpty } /// Returns *true* if the credentials required for account creation have been provided. diff --git a/WordPressAuthenticator/Services/LoginFacade.m b/WordPressAuthenticator/Services/LoginFacade.m index 5bde0a61b..3c806cdfc 100644 --- a/WordPressAuthenticator/Services/LoginFacade.m +++ b/WordPressAuthenticator/Services/LoginFacade.m @@ -152,7 +152,7 @@ - (void)signInToSelfHosted:(LoginFields *)loginFields [self.delegate displayLoginMessage:NSLocalizedString(@"Authenticating", nil)]; - NSString *siteUrl = [NSURL IDNEncodedURL:loginFields.siteAddress]; + NSString *siteUrl = [NSURL IDNEncodedURL: loginFields.siteAddress]; [self.wordpressXMLRPCAPIFacade guessXMLRPCURLForSite:siteUrl success:guessXMLRPCURLSuccess failure:guessXMLRPCURLFailure]; } diff --git a/WordPressAuthenticator/Signin/LoginSiteAddressViewController.swift b/WordPressAuthenticator/Signin/LoginSiteAddressViewController.swift index 87d08e017..e43579a17 100644 --- a/WordPressAuthenticator/Signin/LoginSiteAddressViewController.swift +++ b/WordPressAuthenticator/Signin/LoginSiteAddressViewController.swift @@ -143,12 +143,16 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder view.endEditing(true) displayError(message: "") - let siteAddress = WordPressAuthenticator.baseSiteURL(string: loginFields.siteAddress) + // We need to to this here because before this point we need the URL to be pre-validated + // exactly as the user inputs it, and after this point we need the URL to be the base site URL. + // This isn't really great, but it's the only sane solution I could come up with given the current + // architecture of this pod. + loginFields.siteAddress = WordPressAuthenticator.baseSiteURL(string: loginFields.siteAddress) configureViewLoading(true) let facade = WordPressXMLRPCAPIFacade() - facade.guessXMLRPCURL(forSite: siteAddress, success: { [weak self] (url) in + facade.guessXMLRPCURL(forSite: loginFields.siteAddress, success: { [weak self] (url) in // Success! We now know that we have a valid XML-RPC endpoint. // At this point, we do NOT know if this is a WP.com site or a self-hosted site. if let url = url { @@ -302,7 +306,7 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder // MARK: - URL Validation - /// Does a local / quick Site Adrress validation and refreshes the UI with an error + /// Does a local / quick Site Address validation and refreshes the UI with an error /// if necessary. /// /// - Returns: `true` if the Site Address contains a valid URL. `false` otherwise. diff --git a/WordPressAuthenticatorTests/Model/LoginFieldsValidationTests.swift b/WordPressAuthenticatorTests/Model/LoginFieldsValidationTests.swift index 92be83c1e..0f334003f 100644 --- a/WordPressAuthenticatorTests/Model/LoginFieldsValidationTests.swift +++ b/WordPressAuthenticatorTests/Model/LoginFieldsValidationTests.swift @@ -32,7 +32,7 @@ class LoginFieldsValidationTests: XCTestCase { XCTAssertFalse(loginFields.validateSiteForSignin(), "Empty site should not validate.") loginFields.siteAddress = "hostname" - XCTAssertFalse(loginFields.validateSiteForSignin(), "Since we want to validate simple mistakes, to use a hostname you'll need an http:// or https:// prefix.") + XCTAssertTrue(loginFields.validateSiteForSignin(), "Hostnames should validate.") loginFields.siteAddress = "http://hostname" XCTAssert(loginFields.validateSiteForSignin(), "Since we want to validate simple mistakes, to use a hostname you'll need an http:// or https:// prefix.")