Title: [110395] trunk
Revision
110395
Author
[email protected]
Date
2012-03-11 10:34:09 -0700 (Sun, 11 Mar 2012)

Log Message

Web Inspector: console.log attempts to substitute any "%" character in the message.
https://bugs.webkit.org/show_bug.cgi?id=80504

Reviewed by Vsevolod Vlasov.

Source/WebCore:

Test: inspector/console/console-string-format.html

* inspector/front-end/AuditRules.js:
(WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback):
* inspector/front-end/ProfileDataGridTree.js:
* inspector/front-end/ProfilesPanel.js:
(WebInspector.ProfilesPanel.prototype._reportHeapSnapshotProgress):
* inspector/front-end/utilities.js:

LayoutTests:

* inspector/console/console-string-format-expected.txt: Added.
* inspector/console/console-string-format.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (110394 => 110395)


--- trunk/LayoutTests/ChangeLog	2012-03-11 16:35:35 UTC (rev 110394)
+++ trunk/LayoutTests/ChangeLog	2012-03-11 17:34:09 UTC (rev 110395)
@@ -1,3 +1,13 @@
+2012-03-11  Pavel Feldman  <[email protected]>
+
+        Web Inspector: console.log attempts to substitute any "%" character in the message.
+        https://bugs.webkit.org/show_bug.cgi?id=80504
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/console/console-string-format-expected.txt: Added.
+        * inspector/console/console-string-format.html: Added.
+
 2012-03-11  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: Network panel does not show responses for application/json data

Added: trunk/LayoutTests/inspector/console/console-string-format-expected.txt (0 => 110395)


--- trunk/LayoutTests/inspector/console/console-string-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/console/console-string-format-expected.txt	2012-03-11 17:34:09 UTC (rev 110395)
@@ -0,0 +1,11 @@
+Tests that formatting processes '%' properly in case of missing formatters.
+
+String.sprintf(%T, 1) = "%T"
+String.sprintf(10% x 20%, of the original) = "10% x 20%"
+String.sprintf(%%, ) = "%%"
+String.sprintf(%, ) = "%"
+String.sprintf(% %d, 1) = "% 1"
+String.sprintf(%d % %s, 1, foo) = "1 % foo"
+String.sprintf(%.2f, 0.12345) = "0.12"
+String.sprintf(foo%555 bar, ) = "foo%555 bar"
+

Added: trunk/LayoutTests/inspector/console/console-string-format.html (0 => 110395)


--- trunk/LayoutTests/inspector/console/console-string-format.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/console/console-string-format.html	2012-03-11 17:34:09 UTC (rev 110395)
@@ -0,0 +1,31 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+function test()
+{
+    var params = [
+        ["%T", 1],
+        ["10% x 20%", "of the original"],
+        ["%%", ""],
+        ["%", ""],
+        ["% %d", 1],
+        ["%d % %s", 1, "foo"],
+        ["%.2f", 0.12345],
+        ["foo%555 bar", ""],
+    ];
+    for (var i = 0; i < params.length; ++i)
+        InspectorTest.addResult("String.sprintf(" + params[i].join(", ") + ") = \"" + String.sprintf.apply(String, params[i]) + "\"");
+    InspectorTest.completeTest();
+}
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests that formatting processes '%' properly in case of missing formatters.
+</p>
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (110394 => 110395)


--- trunk/Source/WebCore/ChangeLog	2012-03-11 16:35:35 UTC (rev 110394)
+++ trunk/Source/WebCore/ChangeLog	2012-03-11 17:34:09 UTC (rev 110395)
@@ -1,3 +1,19 @@
+2012-03-11  Pavel Feldman  <[email protected]>
+
+        Web Inspector: console.log attempts to substitute any "%" character in the message.
+        https://bugs.webkit.org/show_bug.cgi?id=80504
+
+        Reviewed by Vsevolod Vlasov.
+
+        Test: inspector/console/console-string-format.html
+
+        * inspector/front-end/AuditRules.js:
+        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.evalCallback.selectorsCallback):
+        * inspector/front-end/ProfileDataGridTree.js:
+        * inspector/front-end/ProfilesPanel.js:
+        (WebInspector.ProfilesPanel.prototype._reportHeapSnapshotProgress):
+        * inspector/front-end/utilities.js:
+
 2012-03-11  Andrey Kosyakov  <[email protected]>
 
         Web Inspector: use monotonically increasing time in timeline agent

Modified: trunk/Source/WebCore/inspector/front-end/AuditRules.js (110394 => 110395)


--- trunk/Source/WebCore/inspector/front-end/AuditRules.js	2012-03-11 16:35:35 UTC (rev 110394)
+++ trunk/Source/WebCore/inspector/front-end/AuditRules.js	2012-03-11 17:34:09 UTC (rev 110395)
@@ -358,7 +358,7 @@
                     var pctUnused = Math.round(100 * unusedStylesheetSize / stylesheetSize);
                     if (!summary)
                         summary = result.addChild("", true);
-                    var entry = summary.addFormatted("%s: %s (%d%%) is not used by the current page.", url, Number.bytesToString(unusedStylesheetSize), pctUnused);
+                    var entry = summary.addFormatted("%s: %s (%d%) is not used by the current page.", url, Number.bytesToString(unusedStylesheetSize), pctUnused);
 
                     for (var j = 0; j < unusedRules.length; ++j)
                         entry.addSnippet(unusedRules[j]);
@@ -370,7 +370,7 @@
                     return callback(null);
 
                 var totalUnusedPercent = Math.round(100 * totalUnusedStylesheetSize / totalStylesheetSize);
-                summary.value = String.sprintf("%s (%d%%) of CSS is not used by the current page.", Number.bytesToString(totalUnusedStylesheetSize), totalUnusedPercent);
+                summary.value = String.sprintf("%s (%d%) of CSS is not used by the current page.", Number.bytesToString(totalUnusedStylesheetSize), totalUnusedPercent);
 
                 callback(result);
             }

Modified: trunk/Source/WebCore/inspector/front-end/ProfileDataGridTree.js (110394 => 110395)


--- trunk/Source/WebCore/inspector/front-end/ProfileDataGridTree.js	2012-03-11 16:35:35 UTC (rev 110394)
+++ trunk/Source/WebCore/inspector/front-end/ProfileDataGridTree.js	2012-03-11 17:34:09 UTC (rev 110395)
@@ -59,17 +59,17 @@
         data["calls"] = this.numberOfCalls;
 
         if (this.profileView.showSelfTimeAsPercent.get())
-            data["self"] = WebInspector.UIString("%.2f%%", this.selfPercent);
+            data["self"] = WebInspector.UIString("%.2f%", this.selfPercent);
         else
             data["self"] = formatMilliseconds(this.selfTime);
 
         if (this.profileView.showTotalTimeAsPercent.get())
-            data["total"] = WebInspector.UIString("%.2f%%", this.totalPercent);
+            data["total"] = WebInspector.UIString("%.2f%", this.totalPercent);
         else
             data["total"] = formatMilliseconds(this.totalTime);
 
         if (this.profileView.showAverageTimeAsPercent.get())
-            data["average"] = WebInspector.UIString("%.2f%%", this.averagePercent);
+            data["average"] = WebInspector.UIString("%.2f%", this.averagePercent);
         else
             data["average"] = formatMilliseconds(this.averageTime);
 

Modified: trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js (110394 => 110395)


--- trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2012-03-11 16:35:35 UTC (rev 110394)
+++ trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js	2012-03-11 17:34:09 UTC (rev 110395)
@@ -859,7 +859,7 @@
     _reportHeapSnapshotProgress: function(done, total)
     {
         if (this.hasTemporaryProfile(WebInspector.DetailedHeapshotProfileType.TypeId)) {
-            this._temporaryRecordingProfile.sidebarElement.subtitle = WebInspector.UIString("%.2f%%", (done / total) * 100);
+            this._temporaryRecordingProfile.sidebarElement.subtitle = WebInspector.UIString("%.2f%", (done / total) * 100);
             this._temporaryRecordingProfile.sidebarElement.wait = true;
             if (done >= total)
                 this._removeTemporaryProfile();

Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (110394 => 110395)


--- trunk/Source/WebCore/inspector/front-end/utilities.js	2012-03-11 16:35:35 UTC (rev 110394)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js	2012-03-11 17:34:09 UTC (rev 110395)
@@ -758,7 +758,7 @@
     return String.vsprintf(format, Array.prototype.slice.call(arguments, 1));
 }
 
-String.tokenizeFormatString = function(format)
+String.tokenizeFormatString = function(format, formatters)
 {
     var tokens = [];
     var substitutionIndex = 0;
@@ -773,22 +773,22 @@
         tokens.push({ type: "specifier", specifier: specifier, precision: precision, substitutionIndex: substitutionIndex });
     }
 
+    function isDigit(c)
+    {
+        return !!/[0-9]/.exec(c);
+    }
+
     var index = 0;
     for (var precentIndex = format.indexOf("%", index); precentIndex !== -1; precentIndex = format.indexOf("%", index)) {
         addStringToken(format.substring(index, precentIndex));
         index = precentIndex + 1;
 
-        if (format[index] === "%") {
-            addStringToken("%");
-            ++index;
-            continue;
-        }
-
-        if (!isNaN(format[index])) {
+        if (isDigit(format[index])) {
             // The first character is a number, it might be a substitution index.
             var number = parseInt(format.substring(index), 10);
-            while (!isNaN(format[index]))
+            while (isDigit(format[index]))
                 ++index;
+
             // If the number is greater than zero and ends with a "$",
             // then this is a substitution index.
             if (number > 0 && format[index] === "$") {
@@ -805,10 +805,17 @@
             precision = parseInt(format.substring(index), 10);
             if (isNaN(precision))
                 precision = 0;
-            while (!isNaN(format[index]))
+
+            while (isDigit(format[index]))
                 ++index;
         }
 
+        if (!(format[index] in formatters)) {
+            addStringToken(format.substring(precentIndex, index + 1));
+            ++index;
+            continue;
+        }
+
         addSpecifierToken(format[index], precision, substitutionIndex);
 
         ++substitutionIndex;
@@ -865,7 +872,7 @@
     }
 
     var result = initialValue;
-    var tokens = String.tokenizeFormatString(format);
+    var tokens = String.tokenizeFormatString(format, formatters);
     var usedSubstitutionIndexes = {};
 
     for (var i = 0; i < tokens.length; ++i) {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to