Skip to content

Commit

Permalink
Fix formatter.commentPermLink (#334)
Browse files Browse the repository at this point in the history
Only return lowercase alphanumeric letters and dashes.
Fixes #330.
  • Loading branch information
nafest authored Sep 26, 2024
1 parent 47d0c68 commit 13523bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions test/comment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('.'));
});
});

0 comments on commit 13523bc

Please sign in to comment.