Changeset 53367 in webkit
- Timestamp:
- Jan 16, 2010 5:03:32 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r53366 r53367 1 2010-01-15 John Sullivan <sullivan@apple.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=33751 and <rdar://problem/7538330> 4 Zip code field is misidentified as street address because id attribute isn't checked. 5 6 Reviewed by Darin Adler 7 8 No new tests. I believe this code is used only by Safari AutoFill, but in any case 9 it does not affect page rendering or anything else at the WebCore/WebKit level. 10 11 * page/Frame.cpp: 12 (WebCore::matchLabelsAgainstString): 13 New function, split out from matchLabelsAgainstElement. 14 (WebCore::Frame::matchLabelsAgainstElement): 15 Now calls matchLabelsAgainstString for the id attribute if no match is found for the name attribute. 16 17 * page/mac/FrameMac.mm: 18 (WebCore::matchLabelsAgainstString): 19 Same as above. This is a parallel copy of the function using Mac-specific data structures. 20 (WebCore::Frame::matchLabelsAgainstElement): 21 Ditto. 22 1 23 2010-01-16 Timothy Hatcher <timothy@apple.com> 2 24 -
trunk/WebCore/page/Frame.cpp
r53218 r53367 495 495 } 496 496 497 String Frame::matchLabelsAgainstElement(const Vector<String>& labels, Element* element) 498 { 499 String name = element->getAttribute(nameAttr); 500 if (name.isEmpty()) 497 static String matchLabelsAgainstString(const Vector<String>& labels, const String& stringToMatch) 498 { 499 if (stringToMatch.isEmpty()) 501 500 return String(); 502 501 502 String mutableStringToMatch = stringToMatch; 503 503 504 // Make numbers and _'s in field names behave like word boundaries, e.g., "address2" 504 replace( name, RegularExpression("\\d", TextCaseSensitive), " ");505 name.replace('_', ' ');506 505 replace(mutableStringToMatch, RegularExpression("\\d", TextCaseSensitive), " "); 506 mutableStringToMatch.replace('_', ' '); 507 507 508 OwnPtr<RegularExpression> regExp(createRegExpForLabels(labels)); 508 // Use the largest match we can find in the whole namestring509 // Use the largest match we can find in the whole string 509 510 int pos; 510 511 int length; … … 513 514 int start = 0; 514 515 do { 515 pos = regExp->match( name, start);516 pos = regExp->match(mutableStringToMatch, start); 516 517 if (pos != -1) { 517 518 length = regExp->matchedLength(); … … 523 524 } 524 525 } while (pos != -1); 525 526 526 527 if (bestPos != -1) 527 return name.substring(bestPos, bestLength);528 return mutableStringToMatch.substring(bestPos, bestLength); 528 529 return String(); 530 } 531 532 String Frame::matchLabelsAgainstElement(const Vector<String>& labels, Element* element) 533 { 534 // Match against the name element, then against the id element if no match is found for the name element. 535 // See 7538330 for one popular site that benefits from the id element check. 536 // FIXME: This code is mirrored in FrameMac.mm. It would be nice to make the Mac code call the platform-agnostic 537 // code, which would require converting the NSArray of NSStrings to a Vector of Strings somewhere along the way. 538 String resultFromNameAttribute = matchLabelsAgainstString(labels, element->getAttribute(nameAttr)); 539 if (!resultFromNameAttribute.isEmpty()) 540 return resultFromNameAttribute; 541 542 return matchLabelsAgainstString(labels, element->getAttribute(idAttr)); 529 543 } 530 544 -
trunk/WebCore/page/mac/FrameMac.mm
r51355 r53367 230 230 } 231 231 232 NSString* Frame::matchLabelsAgainstElement(NSArray* labels, Element* element) 233 { 234 String name = element->getAttribute(nameAttr); 235 if (name.isEmpty()) 236 return nil; 237 232 static NSString *matchLabelsAgainstString(NSArray *labels, const String& stringToMatch) 233 { 234 if (stringToMatch.isEmpty()) 235 return nil; 236 237 String mutableStringToMatch = stringToMatch; 238 238 239 // Make numbers and _'s in field names behave like word boundaries, e.g., "address2" 239 replace( name, RegularExpression("\\d", TextCaseSensitive), " ");240 name.replace('_', ' ');241 240 replace(mutableStringToMatch, RegularExpression("\\d", TextCaseSensitive), " "); 241 mutableStringToMatch.replace('_', ' '); 242 242 243 RegularExpression* regExp = regExpForLabels(labels); 243 // Use the largest match we can find in the whole namestring244 // Use the largest match we can find in the whole string 244 245 int pos; 245 246 int length; … … 248 249 int start = 0; 249 250 do { 250 pos = regExp->match( name, start);251 pos = regExp->match(mutableStringToMatch, start); 251 252 if (pos != -1) { 252 253 length = regExp->matchedLength(); … … 258 259 } 259 260 } while (pos != -1); 260 261 261 262 if (bestPos != -1) 262 return name.substring(bestPos, bestLength);263 return mutableStringToMatch.substring(bestPos, bestLength); 263 264 return nil; 265 } 266 267 NSString* Frame::matchLabelsAgainstElement(NSArray* labels, Element* element) 268 { 269 // Match against the name element, then against the id element if no match is found for the name element. 270 // See 7538330 for one popular site that benefits from the id element check. 271 // FIXME: This code is mirrored in Frame.cpp. It would be nice to make the Mac code call the platform-agnostic 272 // code, which would require converting the NSArray of NSStrings to a Vector of Strings somewhere along the way. 273 String resultFromNameAttribute = matchLabelsAgainstString(labels, element->getAttribute(nameAttr)); 274 if (!resultFromNameAttribute.isEmpty()) 275 return resultFromNameAttribute; 276 277 return matchLabelsAgainstString(labels, element->getAttribute(idAttr)); 264 278 } 265 279
Note: See TracChangeset
for help on using the changeset viewer.