Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ad-hoc): fix card details detectors #400

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct CardExpirationDetector: CardAttributeDetector {
guard let regex = regexProvider.regex(with: "(0[1-9]|1[0-2])[.\\/](\\d{4}|\\d{2})") else {
return nil
}
for (offset, candidate) in candidates.enumerated() {
var matchedExpiration: POScannedCard.Expiration?
for (offset, candidate) in candidates.enumerated().reversed() {
let candidate = candidate.removingCharacters(in: .whitespacesAndNewlines)
let range = NSRange(candidate.startIndex..., in: candidate)
guard let match = regex.firstMatch(in: candidate, range: range) else {
Expand All @@ -36,9 +37,9 @@ struct CardExpirationDetector: CardAttributeDetector {
continue
}
let description = formatter.string(from: String(month) + String(year % 100))
return .init(month: month, year: year, description: description)
matchedExpiration = .init(month: month, year: year, description: description)
}
return nil
return matchedExpiration
}

// MARK: - Private Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ struct CardholderNameDetector: CardAttributeDetector {
}

private func areSimilar(string: String, and secondString: String) -> Bool {
let differencesCount = string.difference(from: secondString).count
return differencesCount <= 1
string == secondString // Check for exact match to avoid potential false negatives, e.g. Visa <-> Lisa
}
}

Expand Down
Loading