Repository navigation
fix(console): preserve non-string first arguments - #5688
Open
PeterlitsZo wants to merge 1 commit into
Open
PeterlitsZo wants to merge 1 commit into
PeterlitsZo wants to merge 1 commit into
Conversation
Only treat string first arguments as format strings and add regression coverage for non-string values. Fixes boa-dev#5687.
abdulhamid999
left a comment
There was a problem hiding this comment.
Reviewed against core/wintertc/src/console/mod.rs and core/wintertc/src/console/tests.rs (static inspection; not compiled locally).
Findings
- Spec & behavior fix: Switching from
data.get_or_undefined(0).to_string(context)?tolet Some(target) = data[0].as_string() else { ... }matches the WHATWG ConsoleFormatterbehavior when the first argument is not a primitive string. It resolves three issues at once:- Avoids throwing
TypeErrorwhen logging aSymbolfollowed by additional arguments. - Avoids invoking custom
.toString()on objects/arrays for multi-argconsole.logcalls (bringing it in line with the single-argument[val]arm). - Prevents
%format specifiers inside stringified arrays/objects (such as['%s']) from consuming subsequent arguments.
- Avoids throwing
- Consistency & safety: All call sites in
core/wintertc/src/console/mod.rspass slices intoformatter, and theelsefallback runs after[]and[val], sodata.len() >= 2holds wheneverdata[0]is indexed. Usingto_string(value, context)joined with" "matches the formatting of[val]and trailing unformatted arguments.
Minor Nits / Suggestions
- Typo in comment (
core/wintertc/src/console/mod.rsinsideformatter):// Only strings are format strings. Otherwises do not format it.->Otherwise, do not format it. - Boxed
Stringobject test (optional):new String('%s')hasas_string() == None(so it rightly avoids format substitution); adding a test case likeconsole.log(new String('%s'), 'tail')inconsole_log_non_string_first_argumentwould explicitly lock in that edge case as well.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes/closes #5687 .
It changes the following: