Changeset 207783 in webkit


Ignore:
Timestamp:
Oct 24, 2016 2:51:44 PM (7 years ago)
Author:
hyatt@apple.com
Message:

[CSS Parser] Fix :lang argument parsing
https://bugs.webkit.org/show_bug.cgi?id=163913

Reviewed by Zalan Bujtas.

  • css/SelectorPseudoClassAndCompatibilityElementMap.in:

Modify the map to support versions of the function pseudos
without the left paren included.

  • css/parser/CSSParserValues.cpp:

(WebCore::CSSParserSelector::setLangArgumentList):

  • css/parser/CSSParserValues.h:

Add a helper to just directly pass an AtomicString Vector through.

  • css/parser/CSSSelectorParser.cpp:

(WebCore::consumeLangArgumentList):
(WebCore::CSSSelectorParser::consumePseudo):
Add a new consumeLangArgumentList to collect the languages into
an AtomicString Vector.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207780 r207783  
     12016-10-24  Dave Hyatt  <hyatt@apple.com>
     2
     3        [CSS Parser] Fix :lang argument parsing
     4        https://bugs.webkit.org/show_bug.cgi?id=163913
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * css/SelectorPseudoClassAndCompatibilityElementMap.in:
     9        Modify the map to support versions of the function pseudos
     10        without the left paren included.
     11
     12        * css/parser/CSSParserValues.cpp:
     13        (WebCore::CSSParserSelector::setLangArgumentList):
     14        * css/parser/CSSParserValues.h:
     15        Add a helper to just directly pass an AtomicString Vector through.
     16
     17        * css/parser/CSSSelectorParser.cpp:
     18        (WebCore::consumeLangArgumentList):
     19        (WebCore::CSSSelectorParser::consumePseudo):
     20        Add a new consumeLangArgumentList to collect the languages into
     21        an AtomicString Vector.
     22
    1232016-10-24  Alex Christensen  <achristensen@webkit.org>
    224
  • trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in

    r205660 r207783  
    11-khtml-drag
     2-webkit-any
    23-webkit-any(
    34-webkit-any-link, PseudoClassAnyLinkDeprecated, PseudoElementUnknown
     
    1415default
    1516#if ENABLE(CSS_SELECTORS_LEVEL4)
     17dir
    1618dir(
    1719#endif
     
    3436indeterminate
    3537invalid
     38lang
    3639lang(
    3740last-child
    3841last-of-type
    3942link
     43matches
    4044matches(
    4145no-button
     46not
    4247not(
     48nth-child
    4349nth-child(
     50nth-last-child
    4451nth-last-child(
     52nth-last-of-type
    4553nth-last-of-type(
     54nth-of-type
    4655nth-of-type(
    4756only-child
     
    5463required
    5564#if ENABLE(CSS_SELECTORS_LEVEL4)
     65role
    5666role(
    5767#endif
  • trunk/Source/WebCore/css/parser/CSSParserValues.cpp

    r207536 r207783  
    411411    m_selector->setLangArgumentList(WTFMove(argumentList));
    412412}
    413    
     413
     414void CSSParserSelector::setLangArgumentList(std::unique_ptr<Vector<AtomicString>> argumentList)
     415{
     416    ASSERT_WITH_MESSAGE(!argumentList->isEmpty(), "No CSS Selector takes an empty argument list.");
     417    m_selector->setLangArgumentList(WTFMove(argumentList));
     418}
     419
    414420void CSSParserSelector::setSelectorList(std::unique_ptr<CSSSelectorList> selectorList)
    415421{
  • trunk/Source/WebCore/css/parser/CSSParserValues.h

    r207536 r207783  
    236236    void adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
    237237    void setLangArgumentList(const Vector<CSSParserString>& stringVector);
     238    void setLangArgumentList(std::unique_ptr<Vector<AtomicString>>);
    238239    void setSelectorList(std::unique_ptr<CSSSelectorList>);
    239240
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp

    r207565 r207783  
    101101}
    102102
     103static void consumeLangArgumentList(std::unique_ptr<Vector<AtomicString>>& argumentList, CSSParserTokenRange& range)
     104{
     105    const CSSParserToken& ident = range.consumeIncludingWhitespace();
     106    if (ident.type() != IdentToken)
     107        return;
     108    argumentList->append(ident.value().toAtomicString());
     109    while (!range.atEnd() && range.peek().type() == CommaToken) {
     110        range.consumeIncludingWhitespace();
     111        const CSSParserToken& ident = range.consumeIncludingWhitespace();
     112        if (ident.type() != IdentToken) {
     113            argumentList->clear();
     114            return;
     115        }
     116        argumentList->append(ident.value().toAtomicString());
     117    }
     118}
     119   
    103120namespace {
    104121
     
    470487        return nullptr;
    471488
    472     switch (selector->pseudoClassType()) {
    473     case CSSSelector::PseudoClassNot: {
    474         std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
    475         block.consumeWhitespace();
    476         if (!innerSelector || !block.atEnd())
    477             return nullptr;
    478         Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
    479         selectorVector.append(WTFMove(innerSelector));
    480         selector->adoptSelectorVector(selectorVector);
    481         return selector;
    482     }
    483     case CSSSelector::PseudoClassNthChild:
    484     case CSSSelector::PseudoClassNthLastChild:
    485     case CSSSelector::PseudoClassNthOfType:
    486     case CSSSelector::PseudoClassNthLastOfType: {
    487         std::pair<int, int> ab;
    488         if (!consumeANPlusB(block, ab))
    489             return nullptr;
    490         block.consumeWhitespace();
    491         if (!block.atEnd())
    492             return nullptr;
    493         selector->setArgument(AtomicString::number(ab.first * ab.second));
    494         return selector;
    495     }
    496     case CSSSelector::PseudoClassLang: {
    497         // FIXME: CSS Selectors Level 4 allows :lang(*-foo)
    498         const CSSParserToken& ident = block.consumeIncludingWhitespace();
    499         if (ident.type() != IdentToken || !block.atEnd())
    500             return nullptr;
    501         selector->setArgument(ident.value().toAtomicString());
    502         return selector;
    503     }
    504     // FIXME-NEWPARSER: Support :host-context
    505     case CSSSelector::PseudoClassAny:
    506     case CSSSelector::PseudoClassHost: {
    507         DisallowPseudoElementsScope scope(this);
    508         std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
    509         *selectorList = consumeCompoundSelectorList(block);
    510         if (!selectorList->isValid() || !block.atEnd())
    511             return nullptr;
    512         selector->setSelectorList(WTFMove(selectorList));
    513         return selector;
    514     }
    515     default:
    516         break;
    517     }
    518 
    519     switch (selector->pseudoElementType()) {
    520     case CSSSelector::PseudoElementCue: {
    521         DisallowPseudoElementsScope scope(this);
    522         std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
    523         *selectorList = consumeCompoundSelectorList(block);
    524         if (!selectorList->isValid() || !block.atEnd())
    525             return nullptr;
    526         selector->setSelectorList(WTFMove(selectorList));
    527         return selector;
    528     }
    529     case CSSSelector::PseudoElementSlotted: {
    530         DisallowPseudoElementsScope scope(this);
    531 
    532         std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
    533         block.consumeWhitespace();
    534         if (!innerSelector || !block.atEnd())
    535             return nullptr;
    536         Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
    537         selectorVector.append(WTFMove(innerSelector));
    538         selector->adoptSelectorVector(selectorVector);
    539         return selector;
    540     }
    541     default:
    542         break;
     489    if (selector->match() == CSSSelector::PseudoClass) {
     490        switch (selector->pseudoClassType()) {
     491        case CSSSelector::PseudoClassNot: {
     492            std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
     493            block.consumeWhitespace();
     494            if (!innerSelector || !block.atEnd())
     495                return nullptr;
     496            Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
     497            selectorVector.append(WTFMove(innerSelector));
     498            selector->adoptSelectorVector(selectorVector);
     499            return selector;
     500        }
     501        case CSSSelector::PseudoClassNthChild:
     502        case CSSSelector::PseudoClassNthLastChild:
     503        case CSSSelector::PseudoClassNthOfType:
     504        case CSSSelector::PseudoClassNthLastOfType: {
     505            std::pair<int, int> ab;
     506            if (!consumeANPlusB(block, ab))
     507                return nullptr;
     508            block.consumeWhitespace();
     509            if (!block.atEnd())
     510                return nullptr;
     511            selector->setArgument(AtomicString::number(ab.first * ab.second));
     512            return selector;
     513        }
     514        case CSSSelector::PseudoClassLang: {
     515            // FIXME: CSS Selectors Level 4 allows :lang(*-foo)
     516            auto argumentList = std::make_unique<Vector<AtomicString>>();
     517            consumeLangArgumentList(argumentList, block);
     518            if (argumentList->isEmpty())
     519                return nullptr;
     520            selector->setLangArgumentList(WTFMove(argumentList));
     521            return selector;
     522        }
     523        // FIXME-NEWPARSER: Support :host-context
     524        case CSSSelector::PseudoClassAny:
     525        case CSSSelector::PseudoClassHost: {
     526            DisallowPseudoElementsScope scope(this);
     527            std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
     528            *selectorList = consumeCompoundSelectorList(block);
     529            if (!selectorList->isValid() || !block.atEnd())
     530                return nullptr;
     531            selector->setSelectorList(WTFMove(selectorList));
     532            return selector;
     533        }
     534        default:
     535            break;
     536        }
     537    }
     538   
     539    if (selector->match() == CSSSelector::PseudoElement) {
     540        switch (selector->pseudoElementType()) {
     541        case CSSSelector::PseudoElementCue: {
     542            DisallowPseudoElementsScope scope(this);
     543            std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
     544            *selectorList = consumeCompoundSelectorList(block);
     545            if (!selectorList->isValid() || !block.atEnd())
     546                return nullptr;
     547            selector->setSelectorList(WTFMove(selectorList));
     548            return selector;
     549        }
     550        case CSSSelector::PseudoElementSlotted: {
     551            DisallowPseudoElementsScope scope(this);
     552
     553            std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
     554            block.consumeWhitespace();
     555            if (!innerSelector || !block.atEnd())
     556                return nullptr;
     557            Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
     558            selectorVector.append(WTFMove(innerSelector));
     559            selector->adoptSelectorVector(selectorVector);
     560            return selector;
     561        }
     562        default:
     563            break;
     564        }
    543565    }
    544566
Note: See TracChangeset for help on using the changeset viewer.