-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
util: logging symbols should convert using String(symbol) #927
Labels
util
Issues and PRs related to the built-in util module.
Comments
Is it the correct behaviour though? I thought it was v8 bug |
Yeah, this is correct per spec and several TC39 meetings. It is dangerous to allow symbols to be implicitly converted to strings (and in some cases you just flat out can't do it, e.g. |
cjihrig
added a commit
that referenced
this issue
Feb 24, 2015
Currently, if util.format() is called with a string as its first argument, and a Symbol as one of the subsequent arguments, an exception is thrown due to an attempted implicit string conversion. This commit causes Symbols to be explicitly converted. Fixes: #927 PR-URL: #931 Reviewed-By: Domenic Denicola <[email protected]>
Closed by ed3b057 |
petkaantonov
pushed a commit
to petkaantonov/io.js
that referenced
this issue
Feb 25, 2015
Currently, if util.format() is called with a string as its first argument, and a Symbol as one of the subsequent arguments, an exception is thrown due to an attempted implicit string conversion. This commit causes Symbols to be explicitly converted. Fixes: nodejs#927 PR-URL: nodejs#931 Reviewed-By: Domenic Denicola <[email protected]>
jasonkarns
added a commit
to testdouble/testdouble.js
that referenced
this issue
Nov 17, 2017
Apparently (nodejs/node#927 (comment)), Symbols cannot be implicitly coerced to string. Template stringification leverages implicit coercion, so we must stringify propKey before sending it to the template. Options for explicitly stringifying: - `String(propKey)` - `String.prototype.toString(propKey)` Differences: ``` > String(undefined) 'undefined' > String.prototype.toString(undefined) '' ``` In this case, `propKey` represents the key for the stubbed function. If the key is `undefined`, it would be implicitly coerced to `"undefined"` as the property key. So `String()` is the explicit converstion we want.
jasonkarns
added a commit
to testdouble/testdouble.js
that referenced
this issue
Nov 18, 2017
Apparently (nodejs/node#927 (comment)), Symbols cannot be implicitly coerced to string. Template stringification leverages implicit coercion, so we must stringify propKey before sending it to the template. Options for explicitly stringifying: - `String(propKey)` - `String.prototype.toString(propKey)` Differences: ``` > String(undefined) 'undefined' > String.prototype.toString(undefined) '' ``` In this case, `propKey` represents the key for the stubbed function. If the key is `undefined`, it would be implicitly coerced to `"undefined"` as the property key. So `String()` is the explicit converstion we want. Four instances of this issue, each where tdFunction is invoked with a dynamic name.
jasonkarns
added a commit
to testdouble/testdouble.js
that referenced
this issue
Nov 18, 2017
Apparently (nodejs/node#927 (comment)), Symbols cannot be implicitly coerced to string. Template stringification leverages implicit coercion, so we must stringify propKey before sending it to the template. Options for explicitly stringifying: - `String(propKey)` - `String.prototype.toString(propKey)` Differences: ``` > String(undefined) 'undefined' > String.prototype.toString(undefined) '' ``` In this case, `propKey` represents the key for the stubbed function. If the key is `undefined`, it would be implicitly coerced to `"undefined"` as the property key. So `String()` is the explicit converstion we want. Four instances of this issue, each where tdFunction is invoked with a dynamic name.
jasonkarns
added a commit
to testdouble/testdouble.js
that referenced
this issue
Jan 17, 2018
Apparently (nodejs/node#927 (comment)), Symbols cannot be implicitly coerced to string. Template stringification leverages implicit coercion, so we must stringify propKey before sending it to the template. Options for explicitly stringifying: - `String(propKey)` - `String.prototype.toString(propKey)` Differences: ``` > String(undefined) 'undefined' > String.prototype.toString(undefined) '' ``` In this case, `propKey` represents the key for the stubbed function. If the key is `undefined`, it would be implicitly coerced to `"undefined"` as the property key. So `String()` is the explicit converstion we want. Four instances of this issue, each where tdFunction is invoked with a dynamic name.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Note that the correct way to stringify a symbol is with the explicit conversion,
String(symbol)
, instead of implicitly with the+
sign.I can get to this after work if nobody else does first.
The text was updated successfully, but these errors were encountered: