Changeset 181762 in webkit


Ignore:
Timestamp:
Mar 19, 2015, 3:37:35 PM (10 years ago)
Author:
achristensen@apple.com
Message:

[Content Extensions] Test regular expression parse failures.
https://bugs.webkit.org/show_bug.cgi?id=142872

Reviewed by Benjamin Poulain.

Source/WebCore:

  • contentextensions/URLFilterParser.cpp:

(WebCore::ContentExtensions::GraphBuilder::finalize):
(WebCore::ContentExtensions::GraphBuilder::quantifyAtom):
(WebCore::ContentExtensions::URLFilterParser::addPattern):
(WebCore::ContentExtensions::URLFilterParser::statusString):

  • contentextensions/URLFilterParser.h:

Changed failures that can never happen to assertions.

Tools:

  • TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:

(TestWebKitAPI::testPatternStatus):
(TestWebKitAPI::TEST_F):
Added tests for each parsing status.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181760 r181762  
     12015-03-19  Alex Christensen  <achristensen@webkit.org>
     2
     3        [Content Extensions] Test regular expression parse failures.
     4        https://bugs.webkit.org/show_bug.cgi?id=142872
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * contentextensions/URLFilterParser.cpp:
     9        (WebCore::ContentExtensions::GraphBuilder::finalize):
     10        (WebCore::ContentExtensions::GraphBuilder::quantifyAtom):
     11        (WebCore::ContentExtensions::URLFilterParser::addPattern):
     12        (WebCore::ContentExtensions::URLFilterParser::statusString):
     13        * contentextensions/URLFilterParser.h:
     14        Changed failures that can never happen to assertions.
     15
    1162015-03-19  Enrica Casucci  <enrica@apple.com>
    217
  • trunk/Source/WebCore/contentextensions/URLFilterParser.cpp

    r181726 r181762  
    478478        }
    479479       
    480         if (!m_openGroups.isEmpty()) {
    481             fail(URLFilterParser::UnclosedGroups);
    482             return;
    483         }
    484 
    485         if (m_subtreeStart != m_subtreeEnd)
    486             m_nfa.setFinal(m_subtreeEnd, m_patternId);
    487         else
    488             fail(URLFilterParser::CannotMatchAnything);
     480        ASSERT_WITH_MESSAGE(m_openGroups.isEmpty(), "An unclosed group should be a parsing error in YARR.");
     481        ASSERT_WITH_MESSAGE(m_subtreeStart != m_subtreeEnd, "This regex cannot match anything");
     482       
     483        m_nfa.setFinal(m_subtreeEnd, m_patternId);
    489484    }
    490485
     
    530525            return;
    531526
    532         if (!m_floatingTerm.isValid())
    533             fail(URLFilterParser::MisplacedQuantifier);
     527        ASSERT(m_floatingTerm.isValid());
    534528
    535529        if (!minimum && maximum == 1)
     
    724718    if (!pattern.containsOnlyASCII())
    725719        return NonASCII;
    726     ASSERT(!pattern.isEmpty());
    727 
    728720    if (pattern.isEmpty())
    729721        return EmptyPattern;
     
    755747    case MatchesEverything:
    756748        return "Matches everything.";
    757     case UnclosedGroups:
    758         return "The expression has unclosed groups.";
    759     case CannotMatchAnything:
    760         return "The pattern cannot match anything.";
    761749    case NonASCII:
    762750        return "Only ASCII characters are supported in pattern.";
    763751    case UnsupportedCharacterClass:
    764752        return "Character class is not supported.";
    765     case MisplacedQuantifier:
    766         return "Quantifier without corresponding term to quantify.";
    767753    case BackReference:
    768754        return "Patterns cannot contain backreferences.";
  • trunk/Source/WebCore/contentextensions/URLFilterParser.h

    r181726 r181762  
    4545        Ok,
    4646        MatchesEverything,
    47         UnclosedGroups,
    48         CannotMatchAnything,
    4947        NonASCII,
    5048        UnsupportedCharacterClass,
    51         MisplacedQuantifier,
    5249        BackReference,
    5350        MisplacedStartOfLine,
  • trunk/Tools/ChangeLog

    r181755 r181762  
     12015-03-19  Alex Christensen  <achristensen@webkit.org>
     2
     3        [Content Extensions] Test regular expression parse failures.
     4        https://bugs.webkit.org/show_bug.cgi?id=142872
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
     9        (TestWebKitAPI::testPatternStatus):
     10        (TestWebKitAPI::TEST_F):
     11        Added tests for each parsing status.
     12
    1132015-03-19  Alex Christensen  <achristensen@webkit.org>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

    r181755 r181762  
    342342}
    343343
    344 static void testPatternStatus(const char* pattern, ContentExtensions::URLFilterParser::ParseStatus status)
     344static void testPatternStatus(String pattern, ContentExtensions::URLFilterParser::ParseStatus status)
    345345{
    346346    ContentExtensions::NFA nfa;
    347347    ContentExtensions::URLFilterParser parser(nfa);
    348     EXPECT_EQ(status, parser.addPattern(ASCIILiteral(pattern), false, 0));
     348    EXPECT_EQ(status, parser.addPattern(pattern, false, 0));
    349349}
    350350   
     
    354354    testPatternStatus("a*b?.*.?[a-z]?[a-z]+", ContentExtensions::URLFilterParser::ParseStatus::Ok);
    355355    testPatternStatus("a*b?.*.?[a-z]?[a-z]", ContentExtensions::URLFilterParser::ParseStatus::Ok);
    356     // FIXME: Add regexes that cause each parse status.
     356    testPatternStatus(".*?a", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     357    testPatternStatus(".*a", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     358   
     359    testPatternStatus("(?!)", ContentExtensions::URLFilterParser::ParseStatus::Group);
     360    testPatternStatus("(?=)", ContentExtensions::URLFilterParser::ParseStatus::Group);
     361    testPatternStatus("(?!a)", ContentExtensions::URLFilterParser::ParseStatus::Group);
     362    testPatternStatus("(?=a)", ContentExtensions::URLFilterParser::ParseStatus::Group);
     363    testPatternStatus("(regex)", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     364    testPatternStatus("(regex", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     365    testPatternStatus("((regex)", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     366    testPatternStatus("(?:regex)", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     367    testPatternStatus("(?:regex", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     368    testPatternStatus("[^.]+", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     369   
     370    testPatternStatus("a++", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     371    testPatternStatus("[a]++", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     372    testPatternStatus("+", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     373   
     374    testPatternStatus("[", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     375    testPatternStatus("[a}", ContentExtensions::URLFilterParser::ParseStatus::YarrError);
     376   
     377    // FIXME: Look into why these do not cause YARR parsing errors.  They probably should.
     378    testPatternStatus("a]", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     379    testPatternStatus("{", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     380    testPatternStatus("{[a]", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     381    testPatternStatus("{0", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     382    testPatternStatus("{0,", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     383    testPatternStatus("{0,1", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     384    testPatternStatus("a{0,1", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     385    testPatternStatus("a{a,b}", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     386
     387    const char nonASCII[2] = {-1, '\0'};
     388    testPatternStatus(nonASCII, ContentExtensions::URLFilterParser::ParseStatus::NonASCII);
     389    testPatternStatus("\\xff", ContentExtensions::URLFilterParser::ParseStatus::NonASCII);
     390   
     391    testPatternStatus("\\x\\r\\n", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     392    testPatternStatus("\\b", ContentExtensions::URLFilterParser::ParseStatus::WordBoundary);
     393    testPatternStatus("[\\d]", ContentExtensions::URLFilterParser::ParseStatus::AtomCharacter);
     394    testPatternStatus("\\d\\D\\w\\s\\v\\h\\i\\c", ContentExtensions::URLFilterParser::ParseStatus::UnsupportedCharacterClass);
     395   
     396    testPatternStatus("this|that", ContentExtensions::URLFilterParser::ParseStatus::Disjunction);
     397    testPatternStatus("a{0,1}b", ContentExtensions::URLFilterParser::ParseStatus::Ok);
     398    testPatternStatus("a{0,2}b", ContentExtensions::URLFilterParser::ParseStatus::InvalidQuantifier);
     399    testPatternStatus("", ContentExtensions::URLFilterParser::ParseStatus::EmptyPattern);
     400    testPatternStatus("$$", ContentExtensions::URLFilterParser::ParseStatus::MisplacedEndOfLine);
     401    testPatternStatus("a^", ContentExtensions::URLFilterParser::ParseStatus::MisplacedStartOfLine);
     402    testPatternStatus("(^)", ContentExtensions::URLFilterParser::ParseStatus::MisplacedStartOfLine);
     403   
     404    testPatternStatus("(a)\\1", ContentExtensions::URLFilterParser::ParseStatus::Ok); // This should be BackReference, right?
    357405}
    358406
Note: See TracChangeset for help on using the changeset viewer.