Changeset 73247 in webkit


Ignore:
Timestamp:
Dec 3, 2010 12:12:10 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-03 Yonathan Randolph <yonathan@gmail.com>

Reviewed by Alexey Proskuryakov.

XPath lexer misinterprets expression starting with "div".
https://bugs.webkit.org/show_bug.cgi?id=50366

  • fast/xpath/ambiguous-operators-expected.txt: Added.
  • fast/xpath/ambiguous-operators.html: Added.

2010-12-03 Yonathan Randolph <yonathan@gmail.com>

Reviewed by Alexey Proskuryakov.

XPath lexer misinterprets expression starting with "div".
https://bugs.webkit.org/show_bug.cgi?id=50366

  • xml/XPathParser.cpp:
  • xml/XPathParser.h: (WebCore::XPath::Parser::isOperatorContext): removed (renamed) (WebCore::XPath::Parser::isBinaryOperatorContext): added
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r73246 r73247  
     12010-12-03  Yonathan Randolph  <yonathan@gmail.com>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        XPath lexer misinterprets expression starting with "div".
     6        https://bugs.webkit.org/show_bug.cgi?id=50366
     7
     8        * fast/xpath/ambiguous-operators-expected.txt: Added.
     9        * fast/xpath/ambiguous-operators.html: Added.
     10
    1112010-12-02  Rob Buis  <rwlbuis@gmail.com>
    212
  • trunk/WebCore/ChangeLog

    r73246 r73247  
     12010-12-03  Yonathan Randolph  <yonathan@gmail.com>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        XPath lexer misinterprets expression starting with "div".
     6        https://bugs.webkit.org/show_bug.cgi?id=50366
     7
     8        * xml/XPathParser.cpp:
     9        * xml/XPathParser.h:
     10        (WebCore::XPath::Parser::isOperatorContext): removed (renamed)
     11        (WebCore::XPath::Parser::isBinaryOperatorContext): added
     12
    1132010-12-02  Rob Buis  <rwlbuis@gmail.com>
    214
  • trunk/WebCore/xml/XPathParser.cpp

    r69437 r73247  
    125125}
    126126
    127 /* Returns whether the last parsed token matches the [32] Operator rule
    128  * (check http://www.w3.org/TR/xpath#exprlex). Necessary to disambiguate
    129  * the tokens.
    130  */
    131 bool Parser::isOperatorContext() const
    132 {
    133     if (m_nextPos == 0)
     127// Returns whether the current token can possibly be a binary operator, given
     128// the previous token. Necessary to disambiguate some of the operators
     129// (* (multiply), div, and, or, mod) in the [32] Operator rule
     130// (check http://www.w3.org/TR/xpath#exprlex).
     131bool Parser::isBinaryOperatorContext() const
     132{
     133    switch (m_lastTokenType) {
     134    case 0:
     135    case '@': case AXISNAME: case '(': case '[': case ',':
     136    case AND: case OR: case MULOP:
     137    case '/': case SLASHSLASH: case '|': case PLUS: case MINUS:
     138    case EQOP: case RELOP:
    134139        return false;
    135 
    136     switch (m_lastTokenType) {
    137         case AND: case OR: case MULOP:
    138         case '/': case SLASHSLASH: case '|': case PLUS: case MINUS:
    139         case EQOP: case RELOP:
    140         case '@': case AXISNAME:   case '(': case '[':
    141             return false;
    142         default:
    143             return true;
     140    default:
     141        return true;
    144142    }
    145143}
     
    280278    char code = peekCurHelper();
    281279    switch (code) {
    282         case '(': case ')': case '[': case ']':
    283         case '@': case ',': case '|':
    284             return makeTokenAndAdvance(code);
    285         case '\'':
    286         case '\"':
    287             return lexString();
    288         case '0': case '1': case '2': case '3': case '4':
    289         case '5': case '6': case '7': case '8': case '9':
     280    case '(': case ')': case '[': case ']':
     281    case '@': case ',': case '|':
     282        return makeTokenAndAdvance(code);
     283    case '\'':
     284    case '\"':
     285        return lexString();
     286    case '0': case '1': case '2': case '3': case '4':
     287    case '5': case '6': case '7': case '8': case '9':
     288        return lexNumber();
     289    case '.': {
     290        char next = peekAheadHelper();
     291        if (next == '.')
     292            return makeTokenAndAdvance(DOTDOT, 2);
     293        if (next >= '0' && next <= '9')
    290294            return lexNumber();
    291         case '.': {
    292             char next = peekAheadHelper();
    293             if (next == '.')
    294                 return makeTokenAndAdvance(DOTDOT, 2);
    295             if (next >= '0' && next <= '9')
    296                 return lexNumber();
    297             return makeTokenAndAdvance('.');
    298         }
    299         case '/':
    300             if (peekAheadHelper() == '/')
    301                 return makeTokenAndAdvance(SLASHSLASH, 2);
    302             return makeTokenAndAdvance('/');
    303         case '+':
    304             return makeTokenAndAdvance(PLUS);
    305         case '-':
    306             return makeTokenAndAdvance(MINUS);
    307         case '=':
    308             return makeTokenAndAdvance(EQOP, EqTestOp::OP_EQ);
    309         case '!':
    310             if (peekAheadHelper() == '=')
    311                 return makeTokenAndAdvance(EQOP, EqTestOp::OP_NE, 2);
     295        return makeTokenAndAdvance('.');
     296    }
     297    case '/':
     298        if (peekAheadHelper() == '/')
     299            return makeTokenAndAdvance(SLASHSLASH, 2);
     300        return makeTokenAndAdvance('/');
     301    case '+':
     302        return makeTokenAndAdvance(PLUS);
     303    case '-':
     304        return makeTokenAndAdvance(MINUS);
     305    case '=':
     306        return makeTokenAndAdvance(EQOP, EqTestOp::OP_EQ);
     307    case '!':
     308        if (peekAheadHelper() == '=')
     309            return makeTokenAndAdvance(EQOP, EqTestOp::OP_NE, 2);
     310        return Token(XPATH_ERROR);
     311    case '<':
     312        if (peekAheadHelper() == '=')
     313            return makeTokenAndAdvance(RELOP, EqTestOp::OP_LE, 2);
     314        return makeTokenAndAdvance(RELOP, EqTestOp::OP_LT);
     315    case '>':
     316        if (peekAheadHelper() == '=')
     317            return makeTokenAndAdvance(RELOP, EqTestOp::OP_GE, 2);
     318        return makeTokenAndAdvance(RELOP, EqTestOp::OP_GT);
     319    case '*':
     320        if (isBinaryOperatorContext())
     321            return makeTokenAndAdvance(MULOP, NumericOp::OP_Mul);
     322        ++m_nextPos;
     323        return Token(NAMETEST, "*");
     324    case '$': { // $ QName
     325        m_nextPos++;
     326        String name;
     327        if (!lexQName(name))
    312328            return Token(XPATH_ERROR);
    313         case '<':
    314             if (peekAheadHelper() == '=')
    315                 return makeTokenAndAdvance(RELOP, EqTestOp::OP_LE, 2);
    316             return makeTokenAndAdvance(RELOP, EqTestOp::OP_LT);
    317         case '>':
    318             if (peekAheadHelper() == '=')
    319                 return makeTokenAndAdvance(RELOP, EqTestOp::OP_GE, 2);
    320             return makeTokenAndAdvance(RELOP, EqTestOp::OP_GT);
    321         case '*':
    322             if (isOperatorContext())
    323                 return makeTokenAndAdvance(MULOP, NumericOp::OP_Mul);
    324             ++m_nextPos;
    325             return Token(NAMETEST, "*");
    326         case '$': { // $ QName
    327             m_nextPos++;
    328             String name;
    329             if (!lexQName(name))
    330                 return Token(XPATH_ERROR);
    331             return Token(VARIABLEREFERENCE, name);
    332         }
     329        return Token(VARIABLEREFERENCE, name);
     330    }
    333331    }
    334332
     
    339337    skipWS();
    340338    // If we're in an operator context, check for any operator names
    341     if (isOperatorContext()) {
     339    if (isBinaryOperatorContext()) {
    342340        if (name == "and") //### hash?
    343341            return Token(AND);
     
    431429
    432430    switch (tok.type) {
    433         case AXISNAME:
    434             yylval->axis = tok.axis;
    435             break;
    436         case MULOP:
    437             yylval->numop = tok.numop;
    438             break;
    439         case RELOP:
    440         case EQOP:
    441             yylval->eqop = tok.eqop;
    442             break;
    443         case NODETYPE:
    444         case PI:
    445         case FUNCTIONNAME:
    446         case LITERAL:
    447         case VARIABLEREFERENCE:
    448         case NUMBER:
    449         case NAMETEST:
    450             yylval->str = new String(tok.str);
    451             registerString(yylval->str);
    452             break;
     431    case AXISNAME:
     432        yylval->axis = tok.axis;
     433        break;
     434    case MULOP:
     435        yylval->numop = tok.numop;
     436        break;
     437    case RELOP:
     438    case EQOP:
     439        yylval->eqop = tok.eqop;
     440        break;
     441    case NODETYPE:
     442    case PI:
     443    case FUNCTIONNAME:
     444    case LITERAL:
     445    case VARIABLEREFERENCE:
     446    case NUMBER:
     447    case NAMETEST:
     448        yylval->str = new String(tok.str);
     449        registerString(yylval->str);
     450        break;
    453451    }
    454452
  • trunk/WebCore/xml/XPathParser.h

    r69437 r73247  
    9292
    9393        private:
    94             bool isOperatorContext() const;
     94            bool isBinaryOperatorContext() const;
    9595
    9696            void skipWS();
Note: See TracChangeset for help on using the changeset viewer.