Closed Bug 1200551 Opened 9 years ago Closed 9 years ago

console.log() formatted output applies only the second specified style when %c%c is part of the string

Categories

(DevTools :: General, defect, P2)

defect

Tracking

(firefox43 fixed)

VERIFIED FIXED
Firefox 43
Tracking Status
firefox43 --- fixed

People

(Reporter: pascalc, Assigned: bgrins)

Details

(Whiteboard: [polish-backlog])

Attachments

(5 files)

The output of Monolog (de facto standard library for PHP development) to the browser is styled incorrectly in Firefox integrated devtools while it is styled correctly in Chrome, Firebug or Safari.

I am attaching to this bug a reduced testcase exposing the incorrect formatting in our devtools. This same testcase is also online there:
http://dev.pascalc.net/console_log_output/example.html

Here is the output of Firefox devtools:
http://dev.pascalc.net/console_log_output/firefox_console_output.png

Here is the output of Chrome:
http://dev.pascalc.net/console_log_output/chrome_console_output.png

Here is the output of Firebug:
http://dev.pascalc.net/console_log_output/firebug_console_output.png

I do not have Safari but a colleague told me that the output of their devtools is the same as Chrome and Firebug on this testcase.

I can reproduce this bug both on the release channel (42) and on Nightly.
Attachment #8655347 - Attachment description: example.html → Testcase exposing the bug
Pascal - excellent bug report, thank you!

Brian: good next bug for someone?
Flags: needinfo?(bgrinstead)
Priority: -- → P2
Whiteboard: [polish-backlog]
The issue seems to be with two %c strings next to each other.  For instance, I believe it styles as expected if I change:

From "%c%cgeneral%c %cINFO%c Information message sent to the console"
To "%c %cgeneral%c %cINFO%c Information message sent to the console"

i.e.

console.log(
    "%c %cgeneral%c %cINFO%c Information message sent to the console",
    "font-weight: normal",
    "font-weight: bold",
    "font-weight: normal",
    "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px",
    "font-weight: normal"
    );
Simple test case:

console.log("%c%chi", "color: green", "background: red")

Should have both a green color and red background but in Firefox it only has green color.  At least, I'm guessing that's what it should be doing - this behavior is poorly specced, but we may as well match what other tools are doing.
Summary: console.log() formatted output in Firefox devtools is styled incorrectly → console.log() formatted output applies only the second specified style when %c%c is part of the string
The 'styles' packet coming from the server only includes the last one in this case.  Which points it to probably being an issue with Console.cpp parsing out the string
I'm pretty sure I tracked down the issue
Assignee: nobody → bgrinstead
Status: NEW → ASSIGNED
Flags: needinfo?(bgrinstead)
Bug 1200551 - Handle multiple %c formatters without a string between them by using only the last one for styling;r=bz,r=past
Attachment #8659358 - Flags: review?(past)
Attachment #8659358 - Flags: review?(bzbarsky)
(In reply to Brian Grinstead [:bgrins] from comment #9)
> Created attachment 8659358 [details]
> MozReview Request: Bug 1200551 - Handle multiple %c formatters without a
> string between them by using only the last one for styling;r=bz,r=past
> 
> Bug 1200551 - Handle multiple %c formatters without a string between them by
> using only the last one for styling;r=bz,r=past

Unfortunately there isn't a spec that I know of for %c handling, but based on what other devtools are doing and what some tools generate (see Comment 0), I think this is the de facto right way to handle the case of:

console.log("%c%chi", "color: green", "background: red")  <-- Should be `background: red` but we currently show it as `color: green`

I've added a test in the patch that handles a variety of %c cases and makes sure it's parsed out as expected
Comment on attachment 8659358 [details]
MozReview Request: Bug 1200551 - Handle multiple %c formatters without a string between them by using only the last one for styling;r=bz,r=past

Andrea knows this code much better than I do...
Attachment #8659358 - Flags: review?(bzbarsky) → review?(amarchesini)
Comment on attachment 8659358 [details]
MozReview Request: Bug 1200551 - Handle multiple %c formatters without a string between them by using only the last one for styling;r=bz,r=past

https://reviewboard.mozilla.org/r/18793/#review16823
Attachment #8659358 - Flags: review?(amarchesini) → review+
Comment on attachment 8659358 [details]
MozReview Request: Bug 1200551 - Handle multiple %c formatters without a string between them by using only the last one for styling;r=bz,r=past

https://reviewboard.mozilla.org/r/18793/#review16889

Yeah, let's go with the flow. If you feel ike it, a PR against https://github.com/DeveloperToolsWG/console-object/blob/master/api.md#format-specifiers to explicitly mention this case would be useful.
Attachment #8659358 - Flags: review?(past) → review+
(In reply to Panos Astithas [:past] from comment #13)
> Comment on attachment 8659358 [details]
> MozReview Request: Bug 1200551 - Handle multiple %c formatters without a
> string between them by using only the last one for styling;r=bz,r=past
> 
> https://reviewboard.mozilla.org/r/18793/#review16889
> 
> Yeah, let's go with the flow. If you feel ike it, a PR against
> https://github.com/DeveloperToolsWG/console-object/blob/master/api.md#format-
> specifiers to explicitly mention this case would be useful.

Alright, I'll do that
Flags: needinfo?(bgrinstead)
https://hg.mozilla.org/mozilla-central/rev/ea0f3fa6453f
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 43
Thanks guys, I confirm that it works now correctly in today's nightly :)
Status: RESOLVED → VERIFIED
Submitted a PR to the console-object repo: https://github.com/DeveloperToolsWG/console-object/pull/34
Flags: needinfo?(bgrinstead)
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: