Changeset 67506 in webkit


Ignore:
Timestamp:
Sep 14, 2010 3:53:02 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-09-14 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

incorrect tabindex parsing
https://bugs.webkit.org/show_bug.cgi?id=21076

Updated our integer parsing for tabindex to use the algorithm from the
HTML5 spec.

Test: fast/parser/tabindex-parsing-2.html

  • html/HTMLElement.cpp: (WebCore::HTMLElement::parseMappedAttribute):
  • html/parser/HTMLParserIdioms.cpp: (WebCore::parseHTMLInteger):
  • html/parser/HTMLParserIdioms.h:

2010-09-14 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

incorrect tabindex parsing
https://bugs.webkit.org/show_bug.cgi?id=21076

  • fast/parser/tabindex-parsing-2-expected.txt: Added.
  • fast/parser/tabindex-parsing-2.html: Added.
    • Test a bunch of corner cases in tabindex parsing.
  • fast/parser/tabindex-parsing-expected.txt:
  • fast/parser/tabindex-parsing.html:
    • Update expected result. This case is actually the one that the original reporter was complaining about.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/text/WTFString.h

    r67423 r67506  
    460460using WTF::appendNumber;
    461461using WTF::charactersAreAllASCII;
     462using WTF::charactersToIntStrict;
     463using WTF::charactersToUIntStrict;
     464using WTF::charactersToInt64Strict;
     465using WTF::charactersToUInt64Strict;
     466using WTF::charactersToIntPtrStrict;
     467using WTF::charactersToInt;
     468using WTF::charactersToUInt;
     469using WTF::charactersToInt64;
     470using WTF::charactersToUInt64;
     471using WTF::charactersToIntPtr;
    462472using WTF::charactersToDouble;
    463473using WTF::charactersToFloat;
    464 using WTF::charactersToInt;
    465474using WTF::equal;
    466475using WTF::equalIgnoringCase;
  • trunk/LayoutTests/ChangeLog

    r67503 r67506  
     12010-09-14  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        incorrect tabindex parsing
     6        https://bugs.webkit.org/show_bug.cgi?id=21076
     7
     8        * fast/parser/tabindex-parsing-2-expected.txt: Added.
     9        * fast/parser/tabindex-parsing-2.html: Added.
     10            - Test a bunch of corner cases in tabindex parsing.
     11        * fast/parser/tabindex-parsing-expected.txt:
     12        * fast/parser/tabindex-parsing.html:
     13            - Update expected result.  This case is actually the one that the
     14              original reporter was complaining about.
     15
    1162010-09-14  Jian Li  <jianli@chromium.org>
    217
  • trunk/LayoutTests/fast/parser/tabindex-parsing-expected.txt

    r32677 r67506  
    1010.tabIndex=7 getAttribute('tabindex')='007'
    1111
    12 This element shouldn't be focusable PASSED
    13 .tabIndex=-1 getAttribute('tabindex')='1px'
     12This element should be focusable PASSED
     13.tabIndex=1 getAttribute('tabindex')='1px'
    1414
    1515This element should be focusable PASSED
  • trunk/LayoutTests/fast/parser/tabindex-parsing.html

    r32677 r67506  
    6060<span id="sp3">Click to test manually</span>
    6161</p>
    62 <p tabindex="1px" onfocus="p4Focused=true" onclick="test(p4Focused,false,4)">This element shouldn't be focusable <br>
     62<p tabindex="1px" onfocus="p4Focused=true" onclick="test(p4Focused,true,4)">This element should be focusable <br>
    6363<span id="sp4">Click to test manually</span>
    6464</p>
  • trunk/WebCore/ChangeLog

    r67505 r67506  
     12010-09-14  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        incorrect tabindex parsing
     6        https://bugs.webkit.org/show_bug.cgi?id=21076
     7
     8        Updated our integer parsing for tabindex to use the algorithm from the
     9        HTML5 spec.
     10
     11        Test: fast/parser/tabindex-parsing-2.html
     12
     13        * html/HTMLElement.cpp:
     14        (WebCore::HTMLElement::parseMappedAttribute):
     15        * html/parser/HTMLParserIdioms.cpp:
     16        (WebCore::parseHTMLInteger):
     17        * html/parser/HTMLParserIdioms.h:
     18
    1192010-09-14  Brent Fulgham  <bfulgham@webkit.org>
    220
  • trunk/WebCore/html/HTMLElement.cpp

    r67292 r67506  
    4040#include "HTMLFormElement.h"
    4141#include "HTMLNames.h"
     42#include "HTMLParserIdioms.h"
    4243#include "RenderWordBreak.h"
    4344#include "ScriptEventListener.h"
     
    143144    } else if (attr->name() == tabindexAttr) {
    144145        indexstring = getAttribute(tabindexAttr);
    145         if (indexstring.length()) {
    146             bool parsedOK;
    147             int tabindex = indexstring.toIntStrict(&parsedOK);
    148             if (parsedOK)
    149                 // Clamp tabindex to the range of 'short' to match Firefox's behavior.
    150                 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
     146        int tabindex = 0;
     147        if (parseHTMLInteger(indexstring, tabindex)) {
     148            // Clamp tabindex to the range of 'short' to match Firefox's behavior.
     149            setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
    151150        }
    152151    } else if (attr->name() == langAttr) {
  • trunk/WebCore/html/parser/HTMLParserIdioms.cpp

    r67423 r67506  
    9292}
    9393
     94// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
     95bool parseHTMLInteger(const String& input, int& value)
     96{
     97    // Step 1
     98    // Step 2
     99    const UChar* position = input.characters();
     100    const UChar* end = position + input.length();
     101
     102    // Step 3
     103    int sign = 1;
     104
     105    // Step 4
     106    while (position < end) {
     107        if (!isHTMLSpace(*position))
     108            break;
     109        ++position;
     110    }
     111
     112    // Step 5
     113    if (position == end)
     114        return false;
     115    ASSERT(position < end);
     116
     117    // Step 6
     118    if (*position == '-') {
     119        sign = -1;
     120        ++position;
     121    } else if (*position == '+')
     122        ++position;
     123    if (position == end)
     124        return false;
     125    ASSERT(position < end);
     126
     127    // Step 7
     128    if (!isASCIIDigit(*position))
     129        return false;
     130
     131    // Step 8
     132    Vector<UChar, 16> digits;
     133    while (position < end) {
     134        if (!isASCIIDigit(*position))
     135            break;
     136        digits.append(*position++);
     137    }
     138
     139    // Step 9
     140    value = sign * charactersToIntStrict(digits.data(), digits.size());
     141    return true;
    94142}
     143
     144}
  • trunk/WebCore/html/parser/HTMLParserIdioms.h

    r67423 r67506  
    4646bool parseToDoubleForNumberType(const String&, double*);
    4747
     48// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
     49bool parseHTMLInteger(const String&, int&);
     50
    4851// Inline implementations of some of the functions declared above.
    4952
  • trunk/WebCore/wml/WMLElement.cpp

    r66498 r67506  
    7373    } else if (attr->name() == HTMLNames::tabindexAttr) {
    7474        String indexstring = attr->value();
    75         if (indexstring.length()) {
    76             bool parsedOK;
    77             int tabindex = indexstring.toIntStrict(&parsedOK);
    78             if (parsedOK)
    79                 // Clamp tabindex to the range of 'short' to match Firefox's behavior.
    80                 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
     75        int tabindex = 0;
     76        if (parseHTMLInteger(tabindex)) {
     77            // Clamp tabindex to the range of 'short' to match Firefox's behavior.
     78            setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short>::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
    8179        }
    8280    }
Note: See TracChangeset for help on using the changeset viewer.