Unnecessary quotes in output from console.* methods
Reported by
klesto...@gmail.com,
Apr 14 2017
|
||||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
Steps to reproduce the problem:
1. Open Console
2. Run console.log('str0', 'str1', 'str2')
3. This command will print:
str0 str1 str2
All strings are printed without quotes and in black color. This is OK.
4. Now run console.log(1, 'str1', 'str2')
What is the expected behavior?
Command from step 4 should print:
1 str1 str2
Where 1 is blue and str1 and str2 are black and without quotes.
What went wrong?
Command from step 4 prints:
1 "str1" "str2"
1 is blue, this is OK, but str1 and str2 are red and printed in quotes. Why? They should be printed in black and without quotes like in step 3.
Did this work before? N/A
Chrome version: 57.0.2987.133 Channel: stable
OS Version: 10.0
Flash Version: Shockwave Flash 25.0 r0
Bug happens only if first parameter is not of type String, so all of this commands also produce buggy output:
console.log(true, 'str1', 'str2')
console.log(null, 'str1', 'str2')
console.log(undefined, 'str1', 'str2')
console.log(Number.NaN, 'str1', 'str2')
console.log([], 'str1', 'str2')
console.log({}, 'str1', 'str2')
console.log(function(){}, 'str1', 'str2')
console.log(() => 1, 'str1', 'str2')
console.log(Symbol, 'str1', 'str2')
The same situation is with console.info(), console.warn() and console.error() methods.
Bug is not happening in latest Firefox, IE and Edge.
,
Apr 14 2017
My guess is that this is a feature (perhaps not completely implemented, but still a feature). Probably in order to distinguish the logged types. I would expect that any combination of strings and non-strings would yield quotes, not just if it is not the first.
,
Apr 14 2017
Logged types are already distinguished by color(blue for number and black for string). Quotes are redundant here. And other browsers don't have such 'feature'.
,
Apr 14 2017
#3 - the fact that other browser do not have such a feature means nothing. The feature set, designs and decisions differ between the browsers. They may seem redundant to you (and this may actually be a bug), but for me, personally, they are not redundant. While colors are distinguishing, I almost never memorize their meaning.
,
Apr 15 2017
Quotes are also confusing. For example, this commands
console.log('"str"')
console.log(0, 'str')
produce very similar outputs, but their string arguments are different! So now, if we look in console output, we have to think what is shown actually. If string is in quotes, then, if it is black, string itself is in quotes, else(if string is red), Chrome added quotes. Very unhandy.
,
Apr 15 2017
Even more confusing example:
console.log('0', '"str"');
console.log(0, 'str');
,
Apr 17 2017
,
Apr 17 2017
Able to reproduce the issue, but it seems more like a feature request, untriaged it so that it gets addressed. Thanks,
,
Apr 18 2017
,
Apr 18 2017
Thank you for the report. Your example in comment #6 does illustrate an interesting case where unhighlighted text matches the highlighted text, since console adds the black quotes. I'm inclined to keep the red strings in quotes. Strings are red to distinguish them easily, while objects are not. Without the black quotes, it's hard to tell whether printed quotes are part of the string or not. Another example: `console.log([], "abc.com", "def.com")` clearly separates two printed urls that would have blended together otherwise. Maybe there are other cases that I'm not aware of? pfeldman wdyt?
,
Apr 19 2017
Why don't you want to make it like it is in Firefox? It just shows strings in orange color and without quotes. String can be first argument, or not first, but it just shown in orange color and without quotes. Very clearly. In example `console.log([], "abc.com", "def.com")` URLs are not blended, because they are separated by space. And in Chrome, Objects and Arrays are easily distinguished by little 'expand me' triangle before them.
,
Dec 8 2017
There are two modes of operation in console logging:
1) message format
2) list of objects
- In the message format mode, the first (or the only) argument is the message template. It should be printed with no quotes in this mode, all other parameters should be formatted into the message format, the remaining ones should be printed as in the 'list' mode.
- In the list mode, values should be printed by value. String values are quoted.
> console.log(1, 'str1', 'str2')
1 "str1" "str2"
> console.log('str0', 'str1', 'str2')
"str0" "str1" "str2"
> console.log('%s', 'str1', 'str2')
str1 "str2"
We should quote string values because it is essential to express where the string begins or ends. Otherwise ambiguity:
> console.log('str0', 'str1 str2')
str0 str1 str2
> console.log('str0 str1', 'str2')
str0 str1 str2
,
Dec 9 2017
I am not sure what you mean by "message template". Is it https://developers.google.com/web/tools/chrome-devtools/console/console-write#string_substitution_and_formatting by any chance? If so, can you detect whether something actually needs substitution (contains %[sidfoOc]) and if not, treat it like a non-message-template argument? |
||||
►
Sign in to add a comment |
||||
Comment 1 by klesto...@gmail.com
, Apr 14 2017