mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +01:00
Merge pull request #5661 from NodeBB/utils-rtrim
Deprecate non-standard `String.prototype.rtrim`
This commit is contained in:
@@ -412,6 +412,10 @@
|
|||||||
(relative_path.length > 0 ? targetLocation.pathname.indexOf(relative_path) === 0 : true) // Subfolder installs need this additional check
|
(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" */
|
||||||
@@ -436,9 +440,11 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DEPRECATED: remove in 1.6
|
||||||
if (typeof String.prototype.rtrim !== 'function') {
|
if (typeof String.prototype.rtrim !== 'function') {
|
||||||
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);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function rtrim(str) {
|
|
||||||
return str.replace(/\s+$/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
Topics.post = function (data, callback) {
|
Topics.post = function (data, callback) {
|
||||||
var uid = data.uid;
|
var uid = data.uid;
|
||||||
data.title = String(data.title).trim();
|
data.title = String(data.title).trim();
|
||||||
@@ -106,7 +102,7 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
if (data.content) {
|
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);
|
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) {
|
function (filteredData, next) {
|
||||||
content = filteredData.content || data.content;
|
content = filteredData.content || data.content;
|
||||||
if (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);
|
check(content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);
|
||||||
|
|||||||
@@ -171,4 +171,11 @@ describe('Utility Methods', function () {
|
|||||||
}
|
}
|
||||||
done();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user