Title: [181840] trunk
- Revision
- 181840
- Author
- [email protected]
- Date
- 2015-03-22 19:04:11 -0700 (Sun, 22 Mar 2015)
Log 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 <[email protected]> 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (181839 => 181840)
--- trunk/Source/WebCore/ChangeLog 2015-03-23 01:28:33 UTC (rev 181839)
+++ trunk/Source/WebCore/ChangeLog 2015-03-23 02:04:11 UTC (rev 181840)
@@ -1,3 +1,19 @@
+2015-03-22 Benjamin Poulain <[email protected]>
+
+ Detect when url filter pattern with groups match the empty string
+ https://bugs.webkit.org/show_bug.cgi?id=142930
+
+ Reviewed by Sam Weinig.
+
+ 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.
+
2015-03-22 Eric Carlson <[email protected]>
[Mac] Enable WIRELESS_PLAYBACK_TARGET for WK1
Modified: trunk/Source/WebCore/contentextensions/URLFilterParser.cpp (181839 => 181840)
--- trunk/Source/WebCore/contentextensions/URLFilterParser.cpp 2015-03-23 01:28:33 UTC (rev 181839)
+++ trunk/Source/WebCore/contentextensions/URLFilterParser.cpp 2015-03-23 02:04:11 UTC (rev 181840)
@@ -175,7 +175,6 @@
ASSERT_WITH_MESSAGE(m_quantifier == AtomQuantifier::One, "Transition to quantified term should only happen once.");
m_quantifier = quantifier;
}
- AtomQuantifier quantifier() const { return m_quantifier; }
unsigned generateGraph(NFA& nfa, uint64_t patternId, unsigned start) const
{
@@ -226,6 +225,25 @@
return m_termType == TermType::CharacterSet && m_atomData.characterSet.characters.bitCount() == 1 && m_atomData.characterSet.characters.get(0);
}
+ bool matchesAtLeastOneCharacter() const
+ {
+ ASSERT(isValid());
+
+ if (m_quantifier == AtomQuantifier::ZeroOrOne || m_quantifier == AtomQuantifier::ZeroOrMore)
+ return false;
+ if (isEndOfLineAssertion())
+ return false;
+
+ if (m_termType == TermType::Group) {
+ for (const Term& term : m_atomData.group.terms) {
+ if (term.matchesAtLeastOneCharacter())
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
Term& operator=(const Term& other)
{
destroy();
@@ -444,7 +462,7 @@
// Check to see if there are any terms without ? or *.
bool matchesEverything = true;
for (const auto& term : m_sunkTerms) {
- if (term.quantifier() == AtomQuantifier::One || term.quantifier() == AtomQuantifier::OneOrMore) {
+ if (term.matchesAtLeastOneCharacter()) {
matchesEverything = false;
break;
}
Modified: trunk/Tools/ChangeLog (181839 => 181840)
--- trunk/Tools/ChangeLog 2015-03-23 01:28:33 UTC (rev 181839)
+++ trunk/Tools/ChangeLog 2015-03-23 02:04:11 UTC (rev 181840)
@@ -1,3 +1,12 @@
+2015-03-22 Benjamin Poulain <[email protected]>
+
+ Detect when url filter pattern with groups match the empty string
+ https://bugs.webkit.org/show_bug.cgi?id=142930
+
+ Reviewed by Sam Weinig.
+
+ * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+
2015-03-22 Anders Carlsson <[email protected]>
_WKWebsiteDataStore should clear WebSQL databases
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (181839 => 181840)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp 2015-03-23 01:28:33 UTC (rev 181839)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp 2015-03-23 02:04:11 UTC (rev 181840)
@@ -404,4 +404,30 @@
testPatternStatus("(a)\\1", ContentExtensions::URLFilterParser::ParseStatus::Ok); // This should be BackReference, right?
}
+TEST_F(ContentExtensionTest, PatternMatchingTheEmptyString)
+{
+ // Simple atoms.
+ testPatternStatus(".*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("a*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus(".?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("a?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+
+ // Character sets.
+ testPatternStatus("[a-z]*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("[a-z]?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+
+ // Groups.
+ testPatternStatus("(foobar)*", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("(foobar)?", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("(.*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("(a*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("(.?)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("(a?)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("([a-z]*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+ testPatternStatus("([a-z]?)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+
+ // Nested groups.
+ testPatternStatus("((foo)?((.)*)(bar)*)", ContentExtensions::URLFilterParser::ParseStatus::MatchesEverything);
+}
+
} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes