<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[190774] branches/safari-601-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/190774">190774</a></dd>
<dt>Author</dt> <dd>lforschler@apple.com</dd>
<dt>Date</dt> <dd>2015-10-08 19:37:29 -0700 (Thu, 08 Oct 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/190602">r190602</a>.  rdar://problem/22995830</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601branchLayoutTestsChangeLog">branches/safari-601-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceWebCoreChangeLog">branches/safari-601-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceWebCorecontentextensionsContentExtensionParsercpp">branches/safari-601-branch/Source/WebCore/contentextensions/ContentExtensionParser.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari601branchLayoutTestshttptestscontentextensionsinvalidselectorexpectedhtml">branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector-expected.html</a></li>
<li><a href="#branchessafari601branchLayoutTestshttptestscontentextensionsinvalidselectorhtml">branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html</a></li>
<li><a href="#branchessafari601branchLayoutTestshttptestscontentextensionsinvalidselectorhtmljson">branches/safari-601-branch/LayoutTests/http/tests/contentextensions/invalid-selector.html.json</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/LayoutTests/ChangeLog (190773 => 190774)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,21 @@
</span><span class="cx"> 2015-10-08  Lucas Forschler  &lt;lforschler@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r190602. rdar://problem/22995830
+
+    2015-10-05  Alex Christensen  &lt;achristensen@webkit.org&gt;
+
+            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  &lt;lforschler@apple.com&gt;
+
</ins><span class="cx">         Merge r190375. rdar://problem/22881748
</span><span class="cx"> 
</span><span class="cx">     2015-09-30  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601branchLayoutTestshttptestscontentextensionsinvalidselectorexpectedhtmlfromrev190602trunkLayoutTestshttptestscontentextensionsinvalidselectorexpectedhtml"></a>
<div class="copfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+This text should be visible because the class is an invalid selector.
</ins></span></pre></div>
<a id="branchessafari601branchLayoutTestshttptestscontentextensionsinvalidselectorhtmlfromrev190602trunkLayoutTestshttptestscontentextensionsinvalidselectorhtml"></a>
<div class="copfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+&lt;body&gt;
+&lt;p class=&quot;valid-selector&quot;&gt;This text should not be visible.&lt;/p&gt;
+&lt;p class=&quot;non-universal-valid-selector&quot;&gt;This text should not be visible.&lt;/p&gt;
+&lt;p class=&quot;body{&quot;&gt;This text should be visible because the class is an invalid selector.&lt;/p&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="branchessafari601branchLayoutTestshttptestscontentextensionsinvalidselectorhtmljsonfromrev190602trunkLayoutTestshttptestscontentextensionsinvalidselectorhtmljson"></a>
<div class="copfile"><h4>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)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+[{
+  &quot;action&quot; : {
+    &quot;type&quot; : &quot;css-display-none&quot;,
+    &quot;selector&quot; : &quot;body{&quot;
+  },
+  &quot;trigger&quot; : {
+    &quot;url-filter&quot; : &quot;.*&quot;
+  }
+},{
+  &quot;action&quot; : {
+    &quot;type&quot; : &quot;css-display-none&quot;,
+    &quot;selector&quot; : &quot;.valid-selector&quot;
+  },
+  &quot;trigger&quot; : {
+    &quot;url-filter&quot; : &quot;.*&quot;
+  }
+},{
+  &quot;action&quot; : {
+    &quot;type&quot; : &quot;css-display-none&quot;,
+    &quot;selector&quot; : &quot;.body{&quot;
+  },
+  &quot;trigger&quot; : {
+    &quot;url-filter&quot; : &quot;.*&quot;
+  }
+},{
+  &quot;action&quot;:{
+         &quot;type&quot;:&quot;css-display-none&quot;,
+         &quot;selector&quot;:&quot;body{background-image: url(http://127.0.0.1:8000/resources/square100.png)}&quot;
+  },
+  &quot;trigger&quot;:{
+         &quot;url-filter&quot;:&quot;html&quot;
+  }
+},{
+  &quot;action&quot; : {
+    &quot;type&quot; : &quot;css-display-none&quot;,
+    &quot;selector&quot; : &quot;.non-universal-valid-selector&quot;
+  },
+  &quot;trigger&quot; : {
+    &quot;url-filter&quot; : &quot;invalid-selector\\.html&quot;
+  }
+}]
</ins></span></pre></div>
<a id="branchessafari601branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebCore/ChangeLog (190773 => 190774)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,26 @@
</span><span class="cx"> 2015-10-08  Lucas Forschler  &lt;lforschler@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r190602. rdar://problem/22995830
+
+    2015-10-05  Alex Christensen  &lt;achristensen@webkit.org&gt;
+
+            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  &lt;lforschler@apple.com&gt;
+
</ins><span class="cx">         Merge r190375. rdar://problem/22881748
</span><span class="cx"> 
</span><span class="cx">     2015-09-30  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601branchSourceWebCorecontentextensionsContentExtensionParsercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebCore/contentextensions/ContentExtensionParser.cpp (190773 => 190774)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -28,6 +28,9 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx"> 
</span><ins>+#include &quot;CSSParser.h&quot;
+#include &quot;CSSParserMode.h&quot;
+#include &quot;CSSSelectorList.h&quot;
</ins><span class="cx"> #include &quot;ContentExtensionError.h&quot;
</span><span class="cx"> #include &quot;ContentExtensionRule.h&quot;
</span><span class="cx"> #include &quot;ContentExtensionsBackend.h&quot;
</span><span class="lines">@@ -174,9 +177,19 @@
</span><span class="cx">     return { };
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static std::error_code loadAction(ExecState&amp; exec, JSObject&amp; ruleObject, Action&amp; action)
</del><ins>+static bool isValidSelector(const String&amp; selector)
</ins><span class="cx"> {
</span><del>-    JSValue actionObject = ruleObject.get(&amp;exec, Identifier::fromString(&amp;exec, &quot;action&quot;));
</del><ins>+    CSSParserContext context(CSSQuirksMode);
+    CSSParser parser(context);
+    CSSSelectorList selectorList;
+    parser.parseSelector(selector, selectorList);
+    return selectorList.isValid();
+}
+
+static std::error_code loadAction(ExecState&amp; exec, const JSObject&amp; ruleObject, Action&amp; action, bool&amp; validSelector)
+{
+    validSelector = true;
+    const JSValue actionObject = ruleObject.get(&amp;exec, Identifier::fromString(&amp;exec, &quot;action&quot;));
</ins><span class="cx">     if (!actionObject || exec.hadException() || !actionObject.isObject())
</span><span class="cx">         return ContentExtensionError::JSONInvalidAction;
</span><span class="cx"> 
</span><span class="lines">@@ -197,7 +210,13 @@
</span><span class="cx">         if (!selector || exec.hadException() || !selector.isString())
</span><span class="cx">             return ContentExtensionError::JSONInvalidCSSDisplayNoneActionType;
</span><span class="cx"> 
</span><del>-        action = Action(ActionType::CSSDisplayNoneSelector, selector.toWTFString(&amp;exec));
</del><ins>+        String s = selector.toWTFString(&amp;exec);
+        if (!isValidSelector(s)) {
+            // Skip rules with invalid selectors to be backwards-compatible.
+            validSelector = false;
+            return { };
+        }
+        action = Action(ActionType::CSSDisplayNoneSelector, s);
</ins><span class="cx">     } else
</span><span class="cx">         return ContentExtensionError::JSONInvalidActionType;
</span><span class="cx"> 
</span><span class="lines">@@ -212,11 +231,13 @@
</span><span class="cx">         return triggerError;
</span><span class="cx"> 
</span><span class="cx">     Action action;
</span><del>-    auto actionError = loadAction(exec, ruleObject, action);
</del><ins>+    bool validSelector;
+    auto actionError = loadAction(exec, ruleObject, action, validSelector);
</ins><span class="cx">     if (actionError)
</span><span class="cx">         return actionError;
</span><span class="cx"> 
</span><del>-    ruleList.append(ContentExtensionRule(trigger, action));
</del><ins>+    if (validSelector)
+        ruleList.append(ContentExtensionRule(trigger, action));
</ins><span class="cx">     return { };
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>