Skip to content

Commit 13523bc

Browse files
authored
Fix formatter.commentPermLink (#334)
Only return lowercase alphanumeric letters and dashes. Fixes #330.
1 parent 47d0c68 commit 13523bc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/formatter.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,15 @@ module.exports = steemAPI => {
183183
.replace(/[^a-zA-Z0-9]+/g, "")
184184
.toLowerCase();
185185
parentPermlink = parentPermlink.replace(/(-\d{8}t\d{9}z)/g, "");
186-
return "re-" + parentAuthor + "-" + parentPermlink + "-" + timeStr;
186+
let permLink =
187+
"re-" + parentAuthor + "-" + parentPermlink + "-" + timeStr;
188+
if (permLink.length > 255) {
189+
// pay respect to STEEMIT_MAX_PERMLINK_LENGTH
190+
permLink.substr(permLink.length - 255, permLink.length);
191+
}
192+
// permlinks must be lower case and not contain anything but
193+
// alphanumeric characters plus dashes
194+
return permLink.toLowerCase().replace(/[^a-z0-9-]+/g, "");
187195
},
188196

189197
amount: function(amount, asset) {

test/comment.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Promise from 'bluebird';
22
import should from 'should';
33
import steem from '../src';
44
import pkg from '../package.json';
5+
import assert from 'assert'
56

67
const username = process.env.STEEM_USERNAME || 'guest123';
78
const password = process.env.STEEM_PASSWORD;
@@ -67,3 +68,14 @@ describe('steem.broadcast:', () => {
6768
});
6869
});
6970
});
71+
72+
describe('commentPermLink:', () => {
73+
it('does not return dots', () => {
74+
var commentPermlink = steem.formatter.commentPermlink(
75+
'foo.bar',
76+
'the-first-physical-foo-bar-ready-to-be-shipped'
77+
);
78+
console.log(commentPermlink);
79+
assert.equal(-1, commentPermlink.indexOf('.'));
80+
});
81+
});

0 commit comments

Comments
 (0)