-
Notifications
You must be signed in to change notification settings - Fork 4.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
Fix #162: allow empty topic list in messages #164
Conversation
1 similar comment
The fix should actually not be required. In the the |
@@ -159,6 +159,9 @@ var inputPostFormatter = function(post) { | |||
post.priority = utils.fromDecimal(post.priority); | |||
|
|||
// fallback | |||
if (post.topics == undefined) { | |||
post.topics = [] | |||
} | |||
if (!utils.isArray(post.topics)) { |
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.
Can you remove this? As the line below already takes care of creating and array if non is given.
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.
If I remove this check, then the sample code crashes with
TypeError: Cannot read property 'length' of undefined
at toHexNative (/usr/lib/node_modules/web3/lib/utils/utils.js:121:27)
at Object.fromAscii (/usr/lib/node_modules/web3/lib/utils/utils.js:139:15)
at /usr/lib/node_modules/web3/lib/web3/formatters.js:168:22
at Array.map (native)
at inputPostFormatter (/usr/lib/node_modules/web3/lib/web3/formatters.js:167:31)
at /usr/lib/node_modules/web3/lib/web3/method.js:86:28
at Array.map (native)
at Method.formatInput (/usr/lib/node_modules/web3/lib/web3/method.js:85:32)
at Method.toPayload (/usr/lib/node_modules/web3/lib/web3/method.js:130:23)
at Method.send (/usr/lib/node_modules/web3/lib/web3/method.js:148:24)
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.
this is the contents of post.topics: [ undefined ]
if I don't specify any in my code.
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.
True, can you refactor the part like this:
// fallback
if (!utils.isArray(post.topics)) {
post.topics = post.topics ? [post.topics] : [];
}
// format the following options
post.topics = post.topics.map(function(topic){
return utils.fromAscii(topic);
});
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.
Sure :)
Fix #162: allow empty topic list in messages
No description provided.