Error in comment links created with steem-js
I'm a bit surprised to have found an issue in steem-js. I'm even more surprised to see that this bug has been there since the very first commit of the code. Documentation is still severely lacking and I had to hack my way through this issue. When using steem-js to make a comment on a post one has to provide a comment permlink. steem-js has a function commentPermlink
to help with creating this permlink. I have been using this function without any issues until today when I used it to comment on a blog post by @diana.catherine.
When using this snippet:
var parentAuthor = 'diana.catherine';
var parentPermlink = 'the-first-physical-steem-coin-ready-to-be-shipped';
var commentPermlink = steem.formatter.commentPermlink(parentAuthor, parentPermlink);
console.log(commentPermlink);
The permlink created looks like this:
re-diana.catherine-the-first-physical-steem-coin-ready-to-be-shipped-20180126t105335010z
Using this permlink to post a comment results in an error:
This is an invalid permlink and when posting an error is returned:
: RPCError: 10 assert_exception: Assert Exception
false: Invalid permlink character: .
Checking the block explorer revealed a second hint. This is just from a random comment on the mentioned post. It shows the dot is removed from the permlink:
I did some further digging and found that condenser has this extra code to further format the permlink in their own function. It is limited to 255 chars and only letters, numbers and dashes are allowed. Excerpt from the TransactionSaga.js
if (permlink.length > 255) {
// STEEMIT_MAX_PERMLINK_LENGTH
permlink = permlink.substring(permlink.length - 255, permlink.length);
}
// only letters numbers and dashes shall survive
permlink = permlink.toLowerCase().replace(/[^a-z0-9-]+/g, '');
When using commentPermlink
it is best to apply the above logic on your code or write your own function to bypass this error.
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @jefpatat I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x