-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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 #8093: Use custom toString method when interpolating objects if implemented #8217
Conversation
…reference instead of value of t
I'm adding some example of the problem to make me understood better: I can confirm that your (so used!) And to write here what I told you yesterday, it could be a BC for those who had a object with a See you! 👋 |
src/shared/util.js
Outdated
@@ -77,7 +77,7 @@ export function isValidArrayIndex (val: any): boolean { | |||
export function toString (val: any): string { | |||
return val == null | |||
? '' | |||
: typeof val === 'object' | |||
: typeof val === 'object' && (!isPlainObject(val) || val.toString === _toString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function can really use early returns now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you want, I kept the original style to make as few changes as possible and let the diff easier to read, but it'll be easy to refactor.
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)Description:
Hi,
When interpolating an object, it uses the JSON.stringify method instead of toString, which is normally the proper method to set a way to convert an object to a string.
This PR allow you to use your custom
toString
method to render your object if it exists. It's tested (I've also added a test for toJson), and it should not be a breaking change.Thanks you for your amazing work folks, and see you in Paris next month!