Skip to content

Commit f2fcbe7

Browse files
authored
IOS-3048: Bugfix/Trailing @ symbol passes validation (#47)
1 parent 4533504 commit f2fcbe7

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
lint:
1818
name: Lint
1919
runs-on: macos-latest
20+
permissions:
21+
pull-requests: write
2022
env:
2123
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2224
steps:

Sources/SpotHeroEmailValidator/SpotHeroEmailValidator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ public class SpotHeroEmailValidator: NSObject {
118118
}
119119

120120
private func splitEmailAddress(_ emailAddress: String) throws -> EmailParts {
121-
let emailAddressParts = emailAddress.split(separator: "@")
122-
123-
guard emailAddressParts.count == 2 else {
124-
// There are either no @ symbols or more than one @ symbol, throw an error
121+
// Ensure there is exactly one @ symbol.
122+
guard emailAddress.filter({ $0 == "@" }).count == 1 else {
125123
throw Error.invalidSyntax
126124
}
127125

126+
let emailAddressParts = emailAddress.split(separator: "@")
127+
128128
// Extract the username from the email address parts
129129
let username = String(emailAddressParts.first ?? "")
130130
// Extract the full domain (including TLD) from the email address parts

Tests/SpotHeroEmailValidatorTests/SpotHeroEmailValidatorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SpotHeroEmailValidatorTests: XCTestCase {
2020
ValidatorTestModel(emailAddress: "test.com", error: .invalidSyntax),
2121
ValidatorTestModel(emailAddress: #"test&*\"@email.com"#, error: .invalidSyntax),
2222
ValidatorTestModel(emailAddress: #"test&*\@email.com"#, error: .invalidSyntax),
23+
ValidatorTestModel(emailAddress: "test@email.com@", error: .invalidSyntax),
2324
// Username Tests
2425
ValidatorTestModel(emailAddress: #"John..Doe@email.com"#, error: .invalidUsername),
2526
ValidatorTestModel(emailAddress: #".JohnDoe@email.com"#, error: .invalidUsername),

0 commit comments

Comments
 (0)