From 13523bc609b43143d0f02ea053820a9f34490a3b Mon Sep 17 00:00:00 2001 From: Stefan Winkler Date: Thu, 26 Sep 2024 18:44:29 +0200 Subject: [PATCH] Fix formatter.commentPermLink (#334) Only return lowercase alphanumeric letters and dashes. Fixes #330. --- src/formatter.js | 10 +++++++++- test/comment.test.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/formatter.js b/src/formatter.js index d9e8bf24..cfdaef08 100755 --- a/src/formatter.js +++ b/src/formatter.js @@ -183,7 +183,15 @@ module.exports = steemAPI => { .replace(/[^a-zA-Z0-9]+/g, "") .toLowerCase(); parentPermlink = parentPermlink.replace(/(-\d{8}t\d{9}z)/g, ""); - return "re-" + parentAuthor + "-" + parentPermlink + "-" + timeStr; + let permLink = + "re-" + parentAuthor + "-" + parentPermlink + "-" + timeStr; + if (permLink.length > 255) { + // pay respect to STEEMIT_MAX_PERMLINK_LENGTH + permLink.substr(permLink.length - 255, permLink.length); + } + // permlinks must be lower case and not contain anything but + // alphanumeric characters plus dashes + return permLink.toLowerCase().replace(/[^a-z0-9-]+/g, ""); }, amount: function(amount, asset) { diff --git a/test/comment.test.js b/test/comment.test.js index ea378f50..6c112a1e 100644 --- a/test/comment.test.js +++ b/test/comment.test.js @@ -2,6 +2,7 @@ import Promise from 'bluebird'; import should from 'should'; import steem from '../src'; import pkg from '../package.json'; +import assert from 'assert' const username = process.env.STEEM_USERNAME || 'guest123'; const password = process.env.STEEM_PASSWORD; @@ -67,3 +68,14 @@ describe('steem.broadcast:', () => { }); }); }); + +describe('commentPermLink:', () => { + it('does not return dots', () => { + var commentPermlink = steem.formatter.commentPermlink( + 'foo.bar', + 'the-first-physical-foo-bar-ready-to-be-shipped' + ); + console.log(commentPermlink); + assert.equal(-1, commentPermlink.indexOf('.')); + }); +}); \ No newline at end of file