Changeset 181762 in webkit
- Timestamp:
- Mar 19, 2015, 3:37:35 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r181760 r181762 1 2015-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 1 16 2015-03-19 Enrica Casucci <enrica@apple.com> 2 17 -
trunk/Source/WebCore/contentextensions/URLFilterParser.cpp
r181726 r181762 478 478 } 479 479 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); 489 484 } 490 485 … … 530 525 return; 531 526 532 if (!m_floatingTerm.isValid()) 533 fail(URLFilterParser::MisplacedQuantifier); 527 ASSERT(m_floatingTerm.isValid()); 534 528 535 529 if (!minimum && maximum == 1) … … 724 718 if (!pattern.containsOnlyASCII()) 725 719 return NonASCII; 726 ASSERT(!pattern.isEmpty());727 728 720 if (pattern.isEmpty()) 729 721 return EmptyPattern; … … 755 747 case MatchesEverything: 756 748 return "Matches everything."; 757 case UnclosedGroups:758 return "The expression has unclosed groups.";759 case CannotMatchAnything:760 return "The pattern cannot match anything.";761 749 case NonASCII: 762 750 return "Only ASCII characters are supported in pattern."; 763 751 case UnsupportedCharacterClass: 764 752 return "Character class is not supported."; 765 case MisplacedQuantifier:766 return "Quantifier without corresponding term to quantify.";767 753 case BackReference: 768 754 return "Patterns cannot contain backreferences."; -
trunk/Source/WebCore/contentextensions/URLFilterParser.h
r181726 r181762 45 45 Ok, 46 46 MatchesEverything, 47 UnclosedGroups,48 CannotMatchAnything,49 47 NonASCII, 50 48 UnsupportedCharacterClass, 51 MisplacedQuantifier,52 49 BackReference, 53 50 MisplacedStartOfLine, -
trunk/Tools/ChangeLog
r181755 r181762 1 2015-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 1 13 2015-03-19 Alex Christensen <achristensen@webkit.org> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp
r181755 r181762 342 342 } 343 343 344 static void testPatternStatus( const char*pattern, ContentExtensions::URLFilterParser::ParseStatus status)344 static void testPatternStatus(String pattern, ContentExtensions::URLFilterParser::ParseStatus status) 345 345 { 346 346 ContentExtensions::NFA nfa; 347 347 ContentExtensions::URLFilterParser parser(nfa); 348 EXPECT_EQ(status, parser.addPattern( ASCIILiteral(pattern), false, 0));348 EXPECT_EQ(status, parser.addPattern(pattern, false, 0)); 349 349 } 350 350 … … 354 354 testPatternStatus("a*b?.*.?[a-z]?[a-z]+", ContentExtensions::URLFilterParser::ParseStatus::Ok); 355 355 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? 357 405 } 358 406
Note:
See TracChangeset
for help on using the changeset viewer.