<!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>[248197] trunk</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/248197">248197</a></dd>
<dt>Author</dt> <dd>drousso@apple.com</dd>
<dt>Date</dt> <dd>2019-08-03 01:52:53 -0700 (Sat, 03 Aug 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: CSS Formatter: comments with an escape character aren't formatted
https://bugs.webkit.org/show_bug.cgi?id=200168

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

Don't allow escaping of the "*" in CSS comments (e.g. `\*/`).

Add additional pretty printing rules for comments so that there's always some space between
them and the surrounding text. This ensures that they don't interfere with readability.

* UserInterface/Workers/Formatter/CSSFormatter.js:
(CSSFormatter.prototype._format):

* UserInterface/Workers/Formatter/FormatterContentBuilder.js:
(FormatterContentBuilder.prototype.get indented): Added.

LayoutTests:

* inspector/formatting/formatting-css.html:
* inspector/formatting/formatting-css-expected.txt:
* inspector/formatting/resources/css-tests/comment.css: Added.
* inspector/formatting/resources/css-tests/comment-expected.css: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorformattingformattingcssexpectedtxt">trunk/LayoutTests/inspector/formatting/formatting-css-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorformattingformattingcsshtml">trunk/LayoutTests/inspector/formatting/formatting-css.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceWorkersFormatterCSSFormatterjs">trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/CSSFormatter.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceWorkersFormatterFormatterContentBuilderjs">trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterContentBuilder.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsinspectorformattingresourcescsstestscommentexpectedcss">trunk/LayoutTests/inspector/formatting/resources/css-tests/comment-expected.css</a></li>
<li><a href="#trunkLayoutTestsinspectorformattingresourcescsstestscommentcss">trunk/LayoutTests/inspector/formatting/resources/css-tests/comment.css</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (248196 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-08-03 07:37:00 UTC (rev 248196)
+++ trunk/LayoutTests/ChangeLog 2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2019-08-03  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: CSS Formatter: comments with an escape character aren't formatted
+        https://bugs.webkit.org/show_bug.cgi?id=200168
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/formatting/formatting-css.html:
+        * inspector/formatting/formatting-css-expected.txt:
+        * inspector/formatting/resources/css-tests/comment.css: Added.
+        * inspector/formatting/resources/css-tests/comment-expected.css: Added.
+
</ins><span class="cx"> 2019-08-02  Andres Gonzalez  <andresg_22@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [ Mac ] Layout Test accessibility/mac/press-not-work-for-disabled-menu-list.html is a flaky failure
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorformattingformattingcssexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/formatting/formatting-css-expected.txt (248196 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/formatting/formatting-css-expected.txt       2019-08-03 07:37:00 UTC (rev 248196)
+++ trunk/LayoutTests/inspector/formatting/formatting-css-expected.txt  2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -5,6 +5,9 @@
</span><span class="cx"> -- Running test case: CSSFormatter.basic.css
</span><span class="cx"> PASS
</span><span class="cx"> 
</span><ins>+-- Running test case: CSSFormatter.comment.css
+PASS
+
</ins><span class="cx"> -- Running test case: CSSFormatter.gradient.css
</span><span class="cx"> PASS
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorformattingformattingcsshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/formatting/formatting-css.html (248196 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/formatting/formatting-css.html       2019-08-03 07:37:00 UTC (rev 248196)
+++ trunk/LayoutTests/inspector/formatting/formatting-css.html  2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -10,6 +10,7 @@
</span><span class="cx"> 
</span><span class="cx">     addFormattingTests(suite, "text/css", [
</span><span class="cx">         "resources/css-tests/basic.css",
</span><ins>+        "resources/css-tests/comment.css",
</ins><span class="cx">         "resources/css-tests/gradient.css",
</span><span class="cx">         "resources/css-tests/keyframes.css",
</span><span class="cx">         "resources/css-tests/media-query.css",
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorformattingresourcescsstestscommentexpectedcss"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/formatting/resources/css-tests/comment-expected.css (0 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/formatting/resources/css-tests/comment-expected.css                          (rev 0)
+++ trunk/LayoutTests/inspector/formatting/resources/css-tests/comment-expected.css     2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -0,0 +1,80 @@
</span><ins>+/* test \*/
+x {
+    a: b;
+    c: d
+}
+/* reset */
+
+/* test \*/
+x {
+    a: b;
+    c: d
+}
+/* reset */
+
+x /* test \*/ {
+    a: b;
+    c: d
+}
+/* reset */
+
+x {
+    /* test \*/
+    a: b;
+    c: d
+}
+/* reset */
+
+x {
+    a /* test \*/: b;
+    c: d
+}
+/* reset */
+
+x {
+    a: /* test \*/ b;
+    c: d
+}
+/* reset */
+
+x {
+    a: b /* test \*/;
+    c: d
+}
+/* reset */
+
+x {
+    a: b;
+    /* test \*/
+    c: d
+}
+/* reset */
+
+x {
+    a: b;
+    c /* test \*/: d
+}
+/* reset */
+
+x {
+    a: b;
+    c: /* test \*/ d
+}
+/* reset */
+
+x {
+    a: b;
+    c: d /* test \*/
+}
+/* reset */
+
+x {
+    a: b;
+    c: d
+}
+/* test \*/
+/* reset */
+
+/* 1 \*/
+/* 2 \*/
+/* 3 \*/
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorformattingresourcescsstestscommentcss"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/formatting/resources/css-tests/comment.css (0 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/formatting/resources/css-tests/comment.css                           (rev 0)
+++ trunk/LayoutTests/inspector/formatting/resources/css-tests/comment.css      2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+/* test \*/
+x{a:b;c:d}
+/* reset */
+
+/* test \*/x{a:b;c:d}
+/* reset */
+
+x/* test \*/{a:b;c:d}
+/* reset */
+
+x{/* test \*/a:b;c:d}
+/* reset */
+
+x{a/* test \*/:b;c:d}
+/* reset */
+
+x{a:/* test \*/b;c:d}
+/* reset */
+
+x{a:b/* test \*/;c:d}
+/* reset */
+
+x{a:b;/* test \*/c:d}
+/* reset */
+
+x{a:b;c/* test \*/:d}
+/* reset */
+
+x{a:b;c:/* test \*/d}
+/* reset */
+
+x{a:b;c:d/* test \*/}
+/* reset */
+
+x{a:b;c:d}/* test \*/
+/* reset */
+
+/* 1 \*/
+/* 2 \*/
+/* 3 \*/
</ins></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (248196 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog    2019-08-03 07:37:00 UTC (rev 248196)
+++ trunk/Source/WebInspectorUI/ChangeLog       2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2019-08-03  Devin Rousso  <drousso@apple.com>
</span><span class="cx"> 
</span><ins>+        Web Inspector: CSS Formatter: comments with an escape character aren't formatted
+        https://bugs.webkit.org/show_bug.cgi?id=200168
+
+        Reviewed by Joseph Pecoraro.
+
+        Don't allow escaping of the "*" in CSS comments (e.g. `\*/`).
+
+        Add additional pretty printing rules for comments so that there's always some space between
+        them and the surrounding text. This ensures that they don't interfere with readability.
+
+        * UserInterface/Workers/Formatter/CSSFormatter.js:
+        (CSSFormatter.prototype._format):
+
+        * UserInterface/Workers/Formatter/FormatterContentBuilder.js:
+        (FormatterContentBuilder.prototype.get indented): Added.
+
+2019-08-03  Devin Rousso  <drousso@apple.com>
+
</ins><span class="cx">         Web Inspector: Console: execution context picker doesn't update when switching to the inferred context from auto
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=200279
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceWorkersFormatterCSSFormatterjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/CSSFormatter.js (248196 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/CSSFormatter.js      2019-08-03 07:37:00 UTC (rev 248196)
+++ trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/CSSFormatter.js 2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -76,6 +76,8 @@
</span><span class="cx">         const removeSpaceBefore = new Set([`,`, `(`, `)`, `}`, `:`, `;`]);
</span><span class="cx">         const removeSpaceAfter = new Set([`(`, `{`, `}`, `,`, `!`, `;`]);
</span><span class="cx"> 
</span><ins>+        const whitespaceOnlyRegExp = /^\s*$/;
+
</ins><span class="cx">         const inAtRuleRegExp = /^\s*@[a-zA-Z][-a-zA-Z]+/;
</span><span class="cx">         const inAtRuleBeforeParenthesisRegExp = /^\s*@[a-zA-Z][-a-zA-Z]+$/;
</span><span class="cx">         const inAtRuleAfterParenthesisRegExp = /^\s*@[a-zA-Z][-a-zA-Z]+[^("':]*\([^"':]*:/;
</span><span class="lines">@@ -92,6 +94,8 @@
</span><span class="cx"> 
</span><span class="cx">             let testCurrentLine = (regExp) => regExp.test(this._builder.currentLine);
</span><span class="cx"> 
</span><ins>+            let inComment = false;
+
</ins><span class="cx">             let inSelector = () => {
</span><span class="cx">                 let nextOpenBrace = this._sourceText.indexOf(`{`, i);
</span><span class="cx">                 if (nextOpenBrace !== -1) {
</span><span class="lines">@@ -225,36 +229,84 @@
</span><span class="cx">             let specialSequenceEnd = null;
</span><span class="cx">             if (quoteTypes.has(c))
</span><span class="cx">                 specialSequenceEnd = c;
</span><del>-            else if (c === `/` && this._sourceText[i + 1] === `*`)
</del><ins>+            else if (c === `/` && this._sourceText[i + 1] === `*`) {
+                inComment = true;
</ins><span class="cx">                 specialSequenceEnd = `*/`;
</span><del>-            else if (c === `u` && this._sourceText[i + 1] === `r` && this._sourceText[i + 2] === `l` && this._sourceText[i + 3] === `(`)
</del><ins>+            } else if (c === `u` && this._sourceText[i + 1] === `r` && this._sourceText[i + 2] === `l` && this._sourceText[i + 3] === `(`)
</ins><span class="cx">                 specialSequenceEnd = `)`;
</span><span class="cx"> 
</span><span class="cx">             if (specialSequenceEnd) {
</span><ins>+                let startIndex = i;
</ins><span class="cx">                 let endIndex = i;
</span><span class="cx">                 do {
</span><span class="cx">                     endIndex = this._sourceText.indexOf(specialSequenceEnd, endIndex + specialSequenceEnd.length);
</span><del>-                } while (endIndex !== -1 && this._sourceText[endIndex - 1] === `\\`);
</del><ins>+                } while (endIndex !== -1 && !inComment && this._sourceText[endIndex - 1] === `\\`);
</ins><span class="cx"> 
</span><span class="cx">                 if (endIndex === -1)
</span><span class="cx">                     endIndex = this._sourceText.length;
</span><ins>+                endIndex += specialSequenceEnd.length;
</ins><span class="cx"> 
</span><del>-                this._builder.appendToken(this._sourceText.substring(i, endIndex + specialSequenceEnd.length), i);
-                i = endIndex + specialSequenceEnd.length - 1; // Account for the iteration of the for loop.
</del><ins>+                let specialSequenceText = this._sourceText.substring(startIndex, endIndex);
</ins><span class="cx"> 
</span><ins>+                let lastSourceNewlineWasMultiple = this._sourceText[startIndex - 1] === `\n` && this._sourceText[startIndex - 2] === `\n`;
+                let lastAppendNewlineWasMultiple = this._builder.lastNewlineAppendWasMultiple;
+
+                let commentOnOwnLine = false;
+                if (inComment) {
+                    commentOnOwnLine = testCurrentLine(whitespaceOnlyRegExp);
+
+                    if (!commentOnOwnLine || lastAppendNewlineWasMultiple) {
+                        while (this._builder.lastTokenWasNewline)
+                            this._builder.removeLastNewline();
+                    }
+
+                    if (commentOnOwnLine) {
+                        if (startIndex > 0 && !this._builder.indented)
+                            this._builder.appendNewline();
+                    } else if (this._builder.currentLine.length && !this._builder.lastTokenWasWhitespace)
+                        this._builder.appendSpace();
+
+                    if (this._builder.lastTokenWasNewline && lastSourceNewlineWasMultiple)
+                        this._builder.appendNewline(true);
+                }
+
+                this._builder.appendToken(specialSequenceText, startIndex);
+
+                i = endIndex;
</ins><span class="cx">                 c = this._sourceText[i];
</span><ins>+
+                if (inComment) {
+                    if (commentOnOwnLine) {
+                        if (lastAppendNewlineWasMultiple && !lastSourceNewlineWasMultiple)
+                            this._builder.appendMultipleNewlines(2);
+                        else
+                            this._builder.appendNewline();
+                    } else if (!/\s/.test(c)) {
+                        if (!testCurrentLine(inAtRuleRegExp) && !inSelector() && !inProperty())
+                            this._builder.appendNewline();
+                        else
+                            this._builder.appendSpace();
+                    }
+                }
+
+                --i; // Account for the iteration of the for loop.
+                c = this._sourceText[i];
+
</ins><span class="cx">                 formatAfter();
</span><span class="cx">                 continue;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             if (/\s/.test(c)) {
</span><del>-                if (c === `\n` && !this._builder.lastTokenWasNewline) {
-                    while (this._builder.lastTokenWasWhitespace)
-                        this._builder.removeLastWhitespace();
-                    if (!removeSpaceAfter.has(this._builder.lastToken))
-                        this._builder.appendNewline();
-                    else
-                        this._builder.appendSpace();
</del><ins>+                if (c === `\n`) {
+                    this._builder.addOriginalLineEnding(i);
+                    if (!this._builder.lastTokenWasNewline) {
+                        while (this._builder.lastTokenWasWhitespace)
+                            this._builder.removeLastWhitespace();
+                        if (!removeSpaceAfter.has(this._builder.lastToken))
+                            this._builder.appendNewline();
+                        else
+                            this._builder.appendSpace();
+                    }
</ins><span class="cx">                 } else if (!this._builder.lastTokenWasWhitespace && !removeSpaceAfter.has(this._builder.lastToken))
</span><span class="cx">                     this._builder.appendSpace();
</span><span class="cx">                 continue;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceWorkersFormatterFormatterContentBuilderjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterContentBuilder.js (248196 => 248197)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterContentBuilder.js   2019-08-03 07:37:00 UTC (rev 248196)
+++ trunk/Source/WebInspectorUI/UserInterface/Workers/Formatter/FormatterContentBuilder.js      2019-08-03 08:52:53 UTC (rev 248197)
</span><span class="lines">@@ -87,6 +87,11 @@
</span><span class="cx">         return this._currentLine;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    get indented()
+    {
+        return this._indent > 0;
+    }
+
</ins><span class="cx">     setOriginalContent(originalContent)
</span><span class="cx">     {
</span><span class="cx">         console.assert(!this._originalContent);
</span></span></pre>
</div>
</div>

</body>
</html>