summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/FindAddress.java
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2018-04-06 15:17:55 -0400
committerTorne (Richard Coles) <torne@google.com>2018-04-06 15:26:36 -0400
commitcfaf8a1e5bea143b9604dd87078d22cd5d9b1b6c (patch)
tree340d1aba1de5a849326c733146f5f9430960a352 /core/java/android/webkit/FindAddress.java
parente7154b6d5a9300c8bfbfc46bf8e65ff1ab446c62 (diff)
Only match addresses without zip codes if at the end.
The old native implementation of findAddress only accepted addresses without zip codes if they appeared at the end of the string. This was probably a bug as the documentation implies this should work in all cases, but fixing this bug has caused a lot of false positives while not fixing very many false negatives and this functionality is being deprecated anyway, so change it back. Fixes: 75409267 Test: tested upstream in chromium; direct copy of that code Change-Id: I3f3c300035cf02a23284737431bc6f94f542cbe7
Diffstat (limited to 'core/java/android/webkit/FindAddress.java')
-rw-r--r--core/java/android/webkit/FindAddress.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/core/java/android/webkit/FindAddress.java b/core/java/android/webkit/FindAddress.java
index 31b242739882..9183227b3962 100644
--- a/core/java/android/webkit/FindAddress.java
+++ b/core/java/android/webkit/FindAddress.java
@@ -429,20 +429,21 @@ class FindAddress {
// At this point we've matched a state; try to match a zip code after it.
Matcher zipMatcher = sWordRe.matcher(content);
- if (zipMatcher.find(stateMatch.end())
- && isValidZipCode(zipMatcher.group(0), stateMatch)) {
- return zipMatcher.end();
+ if (zipMatcher.find(stateMatch.end())) {
+ if (isValidZipCode(zipMatcher.group(0), stateMatch)) {
+ return zipMatcher.end();
+ }
+ } else {
+ // The content ends with a state but no zip
+ // code. This is a legal match according to the
+ // documentation. N.B. This is equivalent to the
+ // original c++ implementation, which only allowed
+ // the zip code to be optional at the end of the
+ // string, which presumably is a bug. We tried
+ // relaxing this to work in other places but it
+ // caused too many false positives.
+ nonZipMatch = stateMatch.end();
}
- // The content ends with a state but no zip
- // code. This is a legal match according to the
- // documentation. N.B. This differs from the
- // original c++ implementation, which only allowed
- // the zip code to be optional at the end of the
- // string, which presumably is a bug. Now we
- // prefer to find a match with a zip code, but
- // remember non-zip matches and return them if
- // necessary.
- nonZipMatch = stateMatch.end();
}
}
}