Changeset 53367 in webkit


Ignore:
Timestamp:
Jan 16, 2010 5:03:32 PM (14 years ago)
Author:
sullivan@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=33751 and <rdar://problem/7538330>
Zip code field is misidentified as street address because id attribute isn't checked.

Reviewed by Darin Adler

No new tests. I believe this code is used only by Safari AutoFill, but in any case
it does not affect page rendering or anything else at the WebCore/WebKit level.

  • page/Frame.cpp:

(WebCore::matchLabelsAgainstString):
New function, split out from matchLabelsAgainstElement.
(WebCore::Frame::matchLabelsAgainstElement):
Now calls matchLabelsAgainstString for the id attribute if no match is found for the name attribute.

  • page/mac/FrameMac.mm:

(WebCore::matchLabelsAgainstString):
Same as above. This is a parallel copy of the function using Mac-specific data structures.
(WebCore::Frame::matchLabelsAgainstElement):
Ditto.

Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53366 r53367  
     12010-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
    1232010-01-16  Timothy Hatcher  <timothy@apple.com>
    224
  • trunk/WebCore/page/Frame.cpp

    r53218 r53367  
    495495}
    496496
    497 String Frame::matchLabelsAgainstElement(const Vector<String>& labels, Element* element)
    498 {
    499     String name = element->getAttribute(nameAttr);
    500     if (name.isEmpty())
     497static String matchLabelsAgainstString(const Vector<String>& labels, const String& stringToMatch)
     498{
     499    if (stringToMatch.isEmpty())
    501500        return String();
    502501
     502    String mutableStringToMatch = stringToMatch;
     503
    503504    // 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   
    507508    OwnPtr<RegularExpression> regExp(createRegExpForLabels(labels));
    508     // Use the largest match we can find in the whole name string
     509    // Use the largest match we can find in the whole string
    509510    int pos;
    510511    int length;
     
    513514    int start = 0;
    514515    do {
    515         pos = regExp->match(name, start);
     516        pos = regExp->match(mutableStringToMatch, start);
    516517        if (pos != -1) {
    517518            length = regExp->matchedLength();
     
    523524        }
    524525    } while (pos != -1);
    525 
     526   
    526527    if (bestPos != -1)
    527         return name.substring(bestPos, bestLength);
     528        return mutableStringToMatch.substring(bestPos, bestLength);
    528529    return String();
     530}
     531   
     532String 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));
    529543}
    530544
  • trunk/WebCore/page/mac/FrameMac.mm

    r51355 r53367  
    230230}
    231231
    232 NSString* Frame::matchLabelsAgainstElement(NSArray* labels, Element* element)
    233 {
    234     String name = element->getAttribute(nameAttr);
    235     if (name.isEmpty())
    236         return nil;
    237 
     232static NSString *matchLabelsAgainstString(NSArray *labels, const String& stringToMatch)
     233{
     234    if (stringToMatch.isEmpty())
     235        return nil;
     236   
     237    String mutableStringToMatch = stringToMatch;
     238   
    238239    // 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   
    242243    RegularExpression* regExp = regExpForLabels(labels);
    243     // Use the largest match we can find in the whole name string
     244    // Use the largest match we can find in the whole string
    244245    int pos;
    245246    int length;
     
    248249    int start = 0;
    249250    do {
    250         pos = regExp->match(name, start);
     251        pos = regExp->match(mutableStringToMatch, start);
    251252        if (pos != -1) {
    252253            length = regExp->matchedLength();
     
    258259        }
    259260    } while (pos != -1);
    260 
     261   
    261262    if (bestPos != -1)
    262         return name.substring(bestPos, bestLength);
     263        return mutableStringToMatch.substring(bestPos, bestLength);
    263264    return nil;
     265}
     266
     267NSString* 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));
    264278}
    265279
Note: See TracChangeset for help on using the changeset viewer.