Title: [190774] branches/safari-601-branch

Diff

Modified: branches/safari-601-branch/LayoutTests/ChangeLog (190773 => 190774)


--- branches/safari-601-branch/LayoutTests/ChangeLog	2015-10-09 02:29:36 UTC (rev 190773)
+++ branches/safari-601-branch/LayoutTests/ChangeLog	2015-10-09 02:37:29 UTC (rev 190774)
@@ -1,5 +1,21 @@
 2015-10-08  Lucas Forschler  <[email protected]>
 
+        Merge r190602. rdar://problem/22995830
+
+    2015-10-05  Alex Christensen  <[email protected]>
+
+            Invalid CSS Selector for Content Blockers invalidates others
+            https://bugs.webkit.org/show_bug.cgi?id=148446
+            rdar://problem/22918235
+
+            Reviewed by Benjamin Poulain.
+
+            * http/tests/contentextensions/invalid-selector-expected.txt: Added.
+            * http/tests/contentextensions/invalid-selector.html: Added.
+            * http/tests/contentextensions/invalid-selector.html.json: Added.
+
+2015-10-08  Lucas Forschler  <[email protected]>
+
         Merge r190375. rdar://problem/22881748
 
     2015-09-30  Myles C. Maxfield  <[email protected]>

Copied: branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector-expected.html (from rev 190602, trunk/LayoutTests/http/tests/contentextensions/invalid-selector-expected.html) (0 => 190774)


--- branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector-expected.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector-expected.html	2015-10-09 02:37:29 UTC (rev 190774)
@@ -0,0 +1 @@
+This text should be visible because the class is an invalid selector.

Copied: branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html (from rev 190602, trunk/LayoutTests/http/tests/contentextensions/invalid-selector.html) (0 => 190774)


--- branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html	2015-10-09 02:37:29 UTC (rev 190774)
@@ -0,0 +1,5 @@
+<body>
+<p class="valid-selector">This text should not be visible.</p>
+<p class="non-universal-valid-selector">This text should not be visible.</p>
+<p class="body{">This text should be visible because the class is an invalid selector.</p>
+</body>

Copied: branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html.json (from rev 190602, trunk/LayoutTests/http/tests/contentextensions/invalid-selector.html.json) (0 => 190774)


--- branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html.json	                        (rev 0)
+++ branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html.json	2015-10-09 02:37:29 UTC (rev 190774)
@@ -0,0 +1,41 @@
+[{
+  "action" : {
+    "type" : "css-display-none",
+    "selector" : "body{"
+  },
+  "trigger" : {
+    "url-filter" : ".*"
+  }
+},{
+  "action" : {
+    "type" : "css-display-none",
+    "selector" : ".valid-selector"
+  },
+  "trigger" : {
+    "url-filter" : ".*"
+  }
+},{
+  "action" : {
+    "type" : "css-display-none",
+    "selector" : ".body{"
+  },
+  "trigger" : {
+    "url-filter" : ".*"
+  }
+},{
+  "action":{
+	 "type":"css-display-none",
+	 "selector":"body{background-image: url(http://127.0.0.1:8000/resources/square100.png)}"
+  },
+  "trigger":{
+	 "url-filter":"html"
+  }
+},{
+  "action" : {
+    "type" : "css-display-none",
+    "selector" : ".non-universal-valid-selector"
+  },
+  "trigger" : {
+    "url-filter" : "invalid-selector\\.html"
+  }
+}]

Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (190773 => 190774)


--- branches/safari-601-branch/Source/WebCore/ChangeLog	2015-10-09 02:29:36 UTC (rev 190773)
+++ branches/safari-601-branch/Source/WebCore/ChangeLog	2015-10-09 02:37:29 UTC (rev 190774)
@@ -1,5 +1,26 @@
 2015-10-08  Lucas Forschler  <[email protected]>
 
+        Merge r190602. rdar://problem/22995830
+
+    2015-10-05  Alex Christensen  <[email protected]>
+
+            Invalid CSS Selector for Content Blockers invalidates others
+            https://bugs.webkit.org/show_bug.cgi?id=148446
+            rdar://problem/22918235
+
+            Reviewed by Benjamin Poulain.
+
+            Test: http/tests/contentextensions/invalid-selector.html
+
+            * contentextensions/ContentExtensionParser.cpp:
+            (WebCore::ContentExtensions::loadTrigger):
+            (WebCore::ContentExtensions::isValidSelector):
+            (WebCore::ContentExtensions::loadAction):
+            (WebCore::ContentExtensions::loadRule):
+            Add a check to see if a selector is valid before adding it.
+
+2015-10-08  Lucas Forschler  <[email protected]>
+
         Merge r190375. rdar://problem/22881748
 
     2015-09-30  Myles C. Maxfield  <[email protected]>

Modified: branches/safari-601-branch/Source/WebCore/contentextensions/ContentExtensionParser.cpp (190773 => 190774)


--- branches/safari-601-branch/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2015-10-09 02:29:36 UTC (rev 190773)
+++ branches/safari-601-branch/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2015-10-09 02:37:29 UTC (rev 190774)
@@ -28,6 +28,9 @@
 
 #if ENABLE(CONTENT_EXTENSIONS)
 
+#include "CSSParser.h"
+#include "CSSParserMode.h"
+#include "CSSSelectorList.h"
 #include "ContentExtensionError.h"
 #include "ContentExtensionRule.h"
 #include "ContentExtensionsBackend.h"
@@ -174,9 +177,19 @@
     return { };
 }
 
-static std::error_code loadAction(ExecState& exec, JSObject& ruleObject, Action& action)
+static bool isValidSelector(const String& selector)
 {
-    JSValue actionObject = ruleObject.get(&exec, Identifier::fromString(&exec, "action"));
+    CSSParserContext context(CSSQuirksMode);
+    CSSParser parser(context);
+    CSSSelectorList selectorList;
+    parser.parseSelector(selector, selectorList);
+    return selectorList.isValid();
+}
+
+static std::error_code loadAction(ExecState& exec, const JSObject& ruleObject, Action& action, bool& validSelector)
+{
+    validSelector = true;
+    const JSValue actionObject = ruleObject.get(&exec, Identifier::fromString(&exec, "action"));
     if (!actionObject || exec.hadException() || !actionObject.isObject())
         return ContentExtensionError::JSONInvalidAction;
 
@@ -197,7 +210,13 @@
         if (!selector || exec.hadException() || !selector.isString())
             return ContentExtensionError::JSONInvalidCSSDisplayNoneActionType;
 
-        action = "" selector.toWTFString(&exec));
+        String s = selector.toWTFString(&exec);
+        if (!isValidSelector(s)) {
+            // Skip rules with invalid selectors to be backwards-compatible.
+            validSelector = false;
+            return { };
+        }
+        action = "" s);
     } else
         return ContentExtensionError::JSONInvalidActionType;
 
@@ -212,11 +231,13 @@
         return triggerError;
 
     Action action;
-    auto actionError = loadAction(exec, ruleObject, action);
+    bool validSelector;
+    auto actionError = loadAction(exec, ruleObject, action, validSelector);
     if (actionError)
         return actionError;
 
-    ruleList.append(ContentExtensionRule(trigger, action));
+    if (validSelector)
+        ruleList.append(ContentExtensionRule(trigger, action));
     return { };
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to