Merge pull request #5661 from NodeBB/utils-rtrim

Deprecate non-standard `String.prototype.rtrim`
v1.18.x
Barış Soner Uşaklı 8 years ago committed by GitHub
commit 17b57be835

@ -412,9 +412,13 @@
(relative_path.length > 0 ? targetLocation.pathname.indexOf(relative_path) === 0 : true) // Subfolder installs need this additional check
);
},
rtrim: function (str) {
return str.replace(/\s+$/g, '');
},
};
/* eslint "no-extend-native": "off" */
/* eslint "no-extend-native": "off" */
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function (prefix) {
if (this.length < prefix.length) {
@ -436,9 +440,11 @@
};
}
// DEPRECATED: remove in 1.6
if (typeof String.prototype.rtrim !== 'function') {
String.prototype.rtrim = function () {
return this.replace(/\s+$/g, '');
console.warn('[deprecated] `String.prototype.rtrim` is deprecated as of NodeBB v1.5; use `utils.rtrim` instead.');
return utils.rtrim(this);
};
}

@ -88,10 +88,6 @@ module.exports = function (Topics) {
], callback);
};
function rtrim(str) {
return str.replace(/\s+$/g, '');
}
Topics.post = function (data, callback) {
var uid = data.uid;
data.title = String(data.title).trim();
@ -106,7 +102,7 @@ module.exports = function (Topics) {
},
function (next) {
if (data.content) {
data.content = rtrim(data.content);
data.content = utils.rtrim(data.content);
}
check(data.content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);
},
@ -239,7 +235,7 @@ module.exports = function (Topics) {
function (filteredData, next) {
content = filteredData.content || data.content;
if (content) {
content = rtrim(content);
content = utils.rtrim(content);
}
check(content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);

@ -171,4 +171,11 @@ describe('Utility Methods', function () {
}
done();
});
it('`utils.rtrim` should remove trailing space', function (done) {
assert.strictEqual(utils.rtrim(' thing '), ' thing');
assert.strictEqual(utils.rtrim('\tthing\t\t'), '\tthing');
assert.strictEqual(utils.rtrim('\t thing \t'), '\t thing');
done();
});
});

Loading…
Cancel
Save