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

fix(warning): stringify args in warn handler #10414

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime-core/src/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function warn(msg: string, ...args: any[]) {
instance,
ErrorCodes.APP_WARN_HANDLER,
[
msg + args.join(''),
msg + args.map(a => JSON.stringify(a)).join(''),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify is not safe, I think it's necessary to write some protective code like a try-catch block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a.toString?.() ?? JSON.stringify(a)?

Copy link
Member Author

@edison1105 edison1105 Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join
https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tostring
Since only the Symbol type throws an exception, maybe only converting the Symbol type is ok. The other types are still handled by the join internal logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically Object.create(null) (any object with a null prototype) would also throw a TypeError when joined.
I don't know whether such arguments are passed to the warn function in the current code base, but let's play it safe to avoid potential bugs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done~

instance && instance.proxy,
trace
.map(
Expand Down
Loading