⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181840 in webkit


Ignore:
Timestamp:
Mar 22, 2015, 7:04:11 PM (11 years ago)
Author:
benjamin@webkit.org
Message:

Detect when url filter pattern with groups match the empty string
https://bugs.webkit.org/show_bug.cgi?id=142930

Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-03-22
Reviewed by Sam Weinig.

Source/WebCore:

The previous test was only accounting for simple atoms. This patch extends
it to groups.

  • contentextensions/URLFilterParser.cpp:

(WebCore::ContentExtensions::Term::quantify):
(WebCore::ContentExtensions::Term::matchesAtLeastOneCharacter):
(WebCore::ContentExtensions::GraphBuilder::finalize):
(WebCore::ContentExtensions::Term::quantifier): Deleted.

Tools:

  • TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181838 r181840  
     12015-03-22  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Detect when url filter pattern with groups match the empty string
     4        https://bugs.webkit.org/show_bug.cgi?id=142930
     5
     6        Reviewed by Sam Weinig.
     7
     8        The previous test was only accounting for simple atoms. This patch extends
     9        it to groups.
     10
     11        * contentextensions/URLFilterParser.cpp:
     12        (WebCore::ContentExtensions::Term::quantify):
     13        (WebCore::ContentExtensions::Term::matchesAtLeastOneCharacter):
     14        (WebCore::ContentExtensions::GraphBuilder::finalize):
     15        (WebCore::ContentExtensions::Term::quantifier): Deleted.
     16
    1172015-03-22  Eric Carlson  <eric.carlson@apple.com>
    218
  • trunk/Source/WebCore/contentextensions/URLFilterParser.cpp

    r181762 r181840  
    176176        m_quantifier = quantifier;
    177177    }
    178     AtomQuantifier quantifier() const { return m_quantifier; }
    179178
    180179    unsigned generateGraph(NFA& nfa, uint64_t patternId, unsigned start) const
     
    225224    {
    226225        return m_termType == TermType::CharacterSet && m_atomData.characterSet.characters.bitCount() == 1 && m_atomData.characterSet.characters.get(0);
     226    }
     227
     228    bool matchesAtLeastOneCharacter() const
     229    {
     230        ASSERT(isValid());
     231
     232        if (m_quantifier == AtomQuantifier::ZeroOrOne || m_quantifier == AtomQuantifier::ZeroOrMore)
     233            return false;
     234        if (isEndOfLineAssertion())
     235            return false;
     236
     237        if (m_termType == TermType::Group) {
     238            for (const Term& term : m_atomData.group.terms) {
     239                if (term.matchesAtLeastOneCharacter())
     240                    return true;
     241            }
     242            return false;
     243        }
     244        return true;
    227245    }
    228246
     
    445463        bool matchesEverything = true;
    446464        for (const auto& term : m_sunkTerms) {
    447             if (term.quantifier() == AtomQuantifier::One || term.quantifier() == AtomQuantifier::OneOrMore) {
     465            if (term.matchesAtLeastOneCharacter()) {
    448466                matchesEverything = false;
    449467                break;
  • trunk/Tools/ChangeLog

    r181837 r181840  
     12015-03-22  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Detect when url filter pattern with groups match the empty string
     4        https://bugs.webkit.org/show_bug.cgi?id=142930
     5
     6        Reviewed by Sam Weinig.
     7
     8        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
     9
    1102015-03-22  Anders Carlsson  <andersca@apple.com>
    211
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

    r181762 r181840  
    405405}
    406406
     407TEST_F(ContentExtensionTest, PatternMatchingTheEmptyString)
     408{
     409    // Simple atoms.
     410    testPatternStatus(".*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     411    testPatternStatus("a*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     412    testPatternStatus(".?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     413    testPatternStatus("a?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     414
     415    // Character sets.
     416    testPatternStatus("[a-z]*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     417    testPatternStatus("[a-z]?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     418
     419    // Groups.
     420    testPatternStatus("(foobar)*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     421    testPatternStatus("(foobar)?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     422    testPatternStatus("(.*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     423    testPatternStatus("(a*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     424    testPatternStatus("(.?)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     425    testPatternStatus("(a?)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     426    testPatternStatus("([a-z]*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     427    testPatternStatus("([a-z]?)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     428
     429    // Nested groups.
     430    testPatternStatus("((foo)?((.)*)(bar)*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
     431}
     432
    407433} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.