-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Console.log bug? #23137
Comments
I agree that it’s super confusing, but it’s by design. If the first argument is a string, it is used as a format string – the
I really think we should improve the |
I’m reopening this so that we can keep it as a todo for the documentation, hope that’s okay. |
I would love to do this one as good first issue, I do have a contribution already but not that relevant, is it okay? |
@lovinglyy Yes, go on. 👍 If you have any questions you can post them here. |
I think our behaviour might not be conforming the Console Standard. If I interpret the spec correctly, we should arrive here with |
Should I wait to see if there will be changes in |
Working on a fix, not sure if it's feasible but it may just be, so we won't have to document this broken behaviour. |
I just checked the spec and to me it leaves a lot of interpretation to the implementer. The Looking at the implementations in browsers it seems like Chrome behaves identical to Node.js and Firefox always formats the output.
Due to this, I would say we can implement this in what ever way we want. |
Yes, our code does not strictly implement the abstractions like Formatter from the spec, but that's something that could be solved with a bit of refactoring. The primary issue is thought that I actually prefer Firefox's formatting to Chrome/Node, but I don't think this is something that can be changed without considerable breakage. |
Two changes here which bring us closer to the console standard: - Arguments to `util.format` are no longer formatted differently depending on their order, with format strings being an exception. - Format specifier formatting is now only triggered if the string actually contains a format string. Under the hood, we now use a single shared function to format the given arguments which will make the code easier to read and modify. PR-URL: nodejs#23162 Fixes: nodejs#23137
Suppose we used console.log as follows:
This will then output the following:
As can be seen the backslash is treated differently between lines.
Also in the actual shell, the colouring is not present in the first line, but is present in the second line.
(boolean is yellow and string is green)
Is this by design or a bug?
The text was updated successfully, but these errors were encountered: