url: require 7+ digits to flag a match as a phone number
AOSP's `Patterns.PHONE` matches any run of 3+ digits, so short codes, ZIP codes, version strings, sport scores, room numbers — anything numeric — surfaced as tappable `tel:` links on Android. iOS `NSDataDetector` is locale-aware and quieter but can still emit short matches in promotional text. Filter both shims at the conventional 7-digit minimum: NANP local is 7 digits, all international numbers run 7+. Below that the match is almost certainly not a dialable number. On Android `canonical_phone` returns an empty string and `run_pattern` drops the record; on iOS the detector block bails early before emitting the match. Fixes user reports of `88773` and `75309` (a famous 7-digit run minus its area code) being incorrectly flagged.
This commit is contained in:
@@ -102,15 +102,21 @@ uint8_t *ux_match_url(const uint16_t *utf16, int32_t len, int32_t *out_size) {
|
||||
NSString *folded = [raw decomposedStringWithCompatibilityMapping];
|
||||
NSMutableString *digits = [NSMutableString stringWithCapacity:folded.length];
|
||||
BOOL seenLetter = NO;
|
||||
NSUInteger digitCount = 0;
|
||||
for (NSUInteger i = 0; i < folded.length; i++) {
|
||||
unichar c = [folded characterAtIndex:i];
|
||||
if ((c >= '0' && c <= '9') || c == '+') {
|
||||
if (seenLetter) break;
|
||||
[digits appendFormat:@"%C", c];
|
||||
if (c >= '0' && c <= '9') digitCount++;
|
||||
} else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
|
||||
seenLetter = YES;
|
||||
}
|
||||
}
|
||||
// 7 digits is the conventional minimum dialable
|
||||
// length; below that the match is almost certainly a
|
||||
// short code / version / ZIP / score, not a phone.
|
||||
if (digitCount < 7) return;
|
||||
url = [NSString stringWithFormat:@"tel:%@", digits];
|
||||
kind = kKindPhone;
|
||||
} else if (result.resultType == NSTextCheckingTypeLink) {
|
||||
|
||||
Reference in New Issue
Block a user