Skip to content

Commit

Permalink
IOS-3048: Bugfix/Trailing @ symbol passes validation (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
khaptonstall committed May 24, 2021
1 parent 4533504 commit f2fcbe7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
lint:
name: Lint
runs-on: macos-latest
permissions:
pull-requests: write
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
Expand Down
8 changes: 4 additions & 4 deletions Sources/SpotHeroEmailValidator/SpotHeroEmailValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ public class SpotHeroEmailValidator: NSObject {
}

private func splitEmailAddress(_ emailAddress: String) throws -> EmailParts {
let emailAddressParts = emailAddress.split(separator: "@")

guard emailAddressParts.count == 2 else {
// There are either no @ symbols or more than one @ symbol, throw an error
// Ensure there is exactly one @ symbol.
guard emailAddress.filter({ $0 == "@" }).count == 1 else {
throw Error.invalidSyntax
}

let emailAddressParts = emailAddress.split(separator: "@")

// Extract the username from the email address parts
let username = String(emailAddressParts.first ?? "")
// Extract the full domain (including TLD) from the email address parts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SpotHeroEmailValidatorTests: XCTestCase {
ValidatorTestModel(emailAddress: "test.com", error: .invalidSyntax),
ValidatorTestModel(emailAddress: #"test&*\"@email.com"#, error: .invalidSyntax),
ValidatorTestModel(emailAddress: #"test&*\@email.com"#, error: .invalidSyntax),
ValidatorTestModel(emailAddress: "test@email.com@", error: .invalidSyntax),
// Username Tests
ValidatorTestModel(emailAddress: #"John..Doe@email.com"#, error: .invalidUsername),
ValidatorTestModel(emailAddress: #".JohnDoe@email.com"#, error: .invalidUsername),
Expand Down

0 comments on commit f2fcbe7

Please sign in to comment.