steemit / steem-js

Steem.js the official JavaScript library for Steem blockchain
https://www.npmjs.com/package/steem
MIT License
472 stars 225 forks source link

Error in comment links created with steem-js #330

Closed JefPatat closed 1 month ago

JefPatat commented 6 years ago

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:

Capture.PNG

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

miraclesam commented 6 years ago

Good to finally meet you sir.. I've been trying to solve the problem but it is quite complex. I tried to upload videos on dtube but I got response like "invalid permlink character: ${s}". Please i need your advice on what to do.