From 320e9af721c3b3d7be305f59718fd92c1d90d9ea Mon Sep 17 00:00:00 2001 From: Stefan Winkler Date: Tue, 30 Jan 2018 23:08:41 +0100 Subject: [PATCH] Fix formatter.commentPermLink 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 b794afd1..979cc1f6 100644 --- a/src/formatter.js +++ b/src/formatter.js @@ -184,7 +184,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