Changeset 209021 in webkit


Ignore:
Timestamp:
Nov 28, 2016 2:30:11 PM (7 years ago)
Author:
hyatt@apple.com
Message:

[CSS Parser] Fix bugs in the @supports parser
https://bugs.webkit.org/show_bug.cgi?id=165115

Reviewed by Zalan Bujtas.

  • css/parser/CSSParserFastPaths.cpp:

(WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue):
Clean up the display property to match the old parser to ensure
that @supports conditions on display are the same.

  • css/parser/CSSSupportsParser.cpp:

(WebCore::CSSSupportsParser::consumeCondition):
(WebCore::CSSSupportsParser::consumeNegation):
(WebCore::CSSSupportsParser::consumeConditionInParenthesis):

  • css/parser/CSSSupportsParser.h:

What follows are all bugs in Blink that need to be fixed to pass our
tests.

Fix the supports parser to allow the whitespace after not/or/and to
be optional. Allow the whitespace following parenthetical conditions
to be optional.

With whitespace being optional, this means that "not(" will parse
as a FunctionToken type, as will "or(" and "and(". Handle this situation
by checking for FunctionToken along with IdentToken and parameterizing
consumeConditionInParenthesis to do the right thing when it starts with
a FunctionToken instead of an IdentToken.

Fix the general enclosure FunctionToken for forward compatibility to require that
the function still be enclosed within parentheses.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r209020 r209021  
     12016-11-28  Dave Hyatt  <hyatt@apple.com>
     2
     3        [CSS Parser] Fix bugs in the @supports parser
     4        https://bugs.webkit.org/show_bug.cgi?id=165115
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * css/parser/CSSParserFastPaths.cpp:
     9        (WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue):
     10        Clean up the display property to match the old parser to ensure
     11        that @supports conditions on display are the same.
     12
     13        * css/parser/CSSSupportsParser.cpp:
     14        (WebCore::CSSSupportsParser::consumeCondition):
     15        (WebCore::CSSSupportsParser::consumeNegation):
     16        (WebCore::CSSSupportsParser::consumeConditionInParenthesis):
     17        * css/parser/CSSSupportsParser.h:
     18        What follows are all bugs in Blink that need to be fixed to pass our
     19        tests.
     20
     21        Fix the supports parser to allow the whitespace after not/or/and to
     22        be optional. Allow the whitespace following parenthetical conditions
     23        to be optional.
     24
     25        With whitespace being optional, this means that "not(" will parse
     26        as a FunctionToken type, as will "or(" and "and(". Handle this situation
     27        by checking for FunctionToken along with IdentToken and parameterizing
     28        consumeConditionInParenthesis to do the right thing when it starts with
     29        a FunctionToken instead of an IdentToken.
     30
     31        Fix the general enclosure FunctionToken for forward compatibility to require that
     32        the function still be enclosed within parentheses.
     33
    1342016-11-28  Mark Lam  <mark.lam@apple.com>
    235
  • trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp

    r208914 r209021  
    549549        // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none
    550550        // flex | inline-flex | -webkit-flex | -webkit-inline-flex | grid | inline-grid
    551         return (valueID >= CSSValueInline && valueID <= CSSValueInlineFlex) || valueID == CSSValueWebkitFlex || valueID == CSSValueWebkitInlineFlex || valueID == CSSValueNone
     551        return (valueID >= CSSValueInline && valueID <= CSSValueContents) || valueID == CSSValueNone
    552552#if ENABLE(CSS_GRID_LAYOUT)
    553553            || (RuntimeEnabledFeatures::sharedFeatures().isCSSGridLayoutEnabled() && (valueID == CSSValueGrid || valueID == CSSValueInlineGrid))
  • trunk/Source/WebCore/css/parser/CSSSupportsParser.cpp

    r205869 r209021  
    4747CSSSupportsParser::SupportsResult CSSSupportsParser::consumeCondition(CSSParserTokenRange range)
    4848{
    49     if (range.peek().type() == IdentToken)
     49    if (range.peek().type() == IdentToken || range.peek().type() == FunctionToken)
    5050        return consumeNegation(range);
    5151
    5252    bool result;
    5353    ClauseType clauseType = Unresolved;
     54   
     55    auto previousTokenType = IdentToken;
    5456
    5557    while (true) {
    56         SupportsResult nextResult = consumeConditionInParenthesis(range);
     58        SupportsResult nextResult = consumeConditionInParenthesis(range, previousTokenType);
    5759        if (nextResult == Invalid)
    5860            return Invalid;
     
    6769        if (range.atEnd())
    6870            break;
    69         if (range.consumeIncludingWhitespace().type() != WhitespaceToken)
    70             return Invalid;
     71        range.consumeWhitespace();
    7172        if (range.atEnd())
    7273            break;
    7374
    74         const CSSParserToken& token = range.consume();
    75         if (token.type() != IdentToken)
     75        const CSSParserToken& token = range.peek();
     76        if (token.type() != IdentToken && token.type() != FunctionToken)
    7677            return Invalid;
     78       
     79        previousTokenType = token.type();
     80       
    7781        if (clauseType == Unresolved)
    7882            clauseType = token.value().length() == 3 ? Conjunction : Disjunction;
     
    8185            return Invalid;
    8286
    83         if (range.consumeIncludingWhitespace().type() != WhitespaceToken)
    84             return Invalid;
     87        if (token.type() == IdentToken)
     88            range.consumeIncludingWhitespace();
    8589    }
    8690    return result ? Supported : Unsupported;
     
    8993CSSSupportsParser::SupportsResult CSSSupportsParser::consumeNegation(CSSParserTokenRange range)
    9094{
    91     ASSERT(range.peek().type() == IdentToken);
    92     if (!equalIgnoringASCIICase(range.consume().value(), "not"))
     95    ASSERT(range.peek().type() == IdentToken || range.peek().type() == FunctionToken);
     96    auto tokenType = range.peek().type();
     97    if (!equalIgnoringASCIICase(range.peek().value(), "not"))
    9398        return Invalid;
    94     if (range.consumeIncludingWhitespace().type() != WhitespaceToken)
    95         return Invalid;
    96     SupportsResult result = consumeConditionInParenthesis(range);
     99    if (range.peek().type() == IdentToken)
     100        range.consumeIncludingWhitespace();
     101    SupportsResult result = consumeConditionInParenthesis(range, tokenType);
    97102    range.consumeWhitespace();
    98103    if (!range.atEnd() || result == Invalid)
     
    101106}
    102107
    103 CSSSupportsParser::SupportsResult CSSSupportsParser::consumeConditionInParenthesis(CSSParserTokenRange& range)
     108CSSSupportsParser::SupportsResult CSSSupportsParser::consumeConditionInParenthesis(CSSParserTokenRange& range, CSSParserTokenType startTokenType)
    104109{
    105     if (range.peek().type() == FunctionToken) {
    106         range.consumeComponentValue();
    107         return Unsupported;
    108     }
    109     if (range.peek().type() != LeftParenthesisToken)
     110    if (startTokenType == IdentToken && range.peek().type() != LeftParenthesisToken)
    110111        return Invalid;
     112
    111113    CSSParserTokenRange innerRange = range.consumeBlock();
    112114    innerRange.consumeWhitespace();
     
    114116    if (result != Invalid)
    115117        return result;
     118   
     119    if (innerRange.peek().type() == FunctionToken) {
     120        innerRange.consumeComponentValue();
     121        return Unsupported;
     122    }
     123
    116124    return innerRange.peek().type() == IdentToken && m_parser.supportsDeclaration(innerRange) ? Supported : Unsupported;
    117125}
  • trunk/Source/WebCore/css/parser/CSSSupportsParser.h

    r205790 r209021  
    3030#pragma once
    3131
     32#include "CSSParserToken.h"
     33
    3234namespace WebCore {
    3335
    3436class CSSParserImpl;
    3537class CSSParserTokenRange;
    36 
     38   
    3739class CSSSupportsParser {
    3840public:
     
    5254    SupportsResult consumeNegation(CSSParserTokenRange);
    5355
    54     SupportsResult consumeConditionInParenthesis(CSSParserTokenRange&);
     56    SupportsResult consumeConditionInParenthesis(CSSParserTokenRange&, CSSParserTokenType);
    5557
    5658    CSSParserImpl& m_parser;
Note: See TracChangeset for help on using the changeset viewer.