Skip to content
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

How do you force format specifiers in console.log format to be treated as literals? #157

Open
rshpount opened this issue Apr 26, 2019 · 3 comments

Comments

@rshpount
Copy link

For instance if I need "console.log("%d %d", 1);" to output "%d 1", how do I force the first "%d" to be treated as a literal and not the format specifier?

Should "%%" which produces "%" as an output added to the Formatter?

@domenic
Copy link
Member

domenic commented Apr 26, 2019

Firefox and Chrome already do this in the way you describe. Good catch. I think we should update the spec to account for it.

@rshpount
Copy link
Author

I have also verified that this is what Chrome 73, Firefox 66 , IE 11, Edge 17, and Safari 12 are doing already.

I have also noticed that Safari 12 does not handle "%" followed by invalid specifier gracefully. For instance in Safari 12, "console.log("%1 %d", 1);" prints "[object Object]d". It probably makes sense to add some language to specify how unsupported specifiers are supposed to be handled, especially if you want to allow future extensions.

@terinjokes
Copy link
Collaborator

%% is clearly an oversight. PRs definitely accepted.

I agree we should add some verbage for handling unknown formatters. I'll think about it this afternoon and post some ideas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants