mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-21 04:01:38 +02:00
fix: remove bidiControls from notification.bodyShort
This commit is contained in:
@@ -300,7 +300,9 @@ const utils = {
|
|||||||
const pattern = (tags || ['']).join('|');
|
const pattern = (tags || ['']).join('|');
|
||||||
return String(str).replace(new RegExp('<(\\/)?(' + (pattern || '[^\\s>]+') + ')(\\s+[^<>]*?)?\\s*(\\/)?>', 'gi'), '');
|
return String(str).replace(new RegExp('<(\\/)?(' + (pattern || '[^\\s>]+') + ')(\\s+[^<>]*?)?\\s*(\\/)?>', 'gi'), '');
|
||||||
},
|
},
|
||||||
|
stripBidiControls: function (input) {
|
||||||
|
return input.replace(/[\u202A-\u202E\u2066-\u2069]/g, '');
|
||||||
|
},
|
||||||
cleanUpTag: function (tag, maxLength) {
|
cleanUpTag: function (tag, maxLength) {
|
||||||
if (typeof tag !== 'string' || !tag.length) {
|
if (typeof tag !== 'string' || !tag.length) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@@ -177,6 +177,9 @@ Notifications.create = async function (data) {
|
|||||||
if (!result.data) {
|
if (!result.data) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (data.bodyShort) {
|
||||||
|
data.bodyShort = utils.stripBidiControls(data.bodyShort);
|
||||||
|
}
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetAdd('notifications', now, data.nid),
|
db.sortedSetAdd('notifications', now, data.nid),
|
||||||
db.setObject(`notifications:${data.nid}`, data),
|
db.setObject(`notifications:${data.nid}`, data),
|
||||||
|
|||||||
@@ -44,6 +44,26 @@ describe('Utility Methods', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('utils.stripBidiControls', () => {
|
||||||
|
it('should remove common bidi embedding and override controls', () => {
|
||||||
|
const input = '\u202AHello\u202C \u202BWorld\u202C \u202DDwellers\u202E';
|
||||||
|
const out = utils.stripBidiControls(input);
|
||||||
|
assert.strictEqual(out, 'Hello World Dwellers');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove bidirectional isolate formatting characters', () => {
|
||||||
|
const input = '\u2066abc\u2067def\u2068ghi\u2069';
|
||||||
|
const out = utils.stripBidiControls(input);
|
||||||
|
assert.strictEqual(out, 'abcdefghi');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should leave normal text unchanged', () => {
|
||||||
|
const input = 'plain text 123';
|
||||||
|
const out = utils.stripBidiControls(input);
|
||||||
|
assert.strictEqual(out, 'plain text 123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should preserve case if requested', (done) => {
|
it('should preserve case if requested', (done) => {
|
||||||
assert.strictEqual(slugify('UPPER CASE', true), 'UPPER-CASE');
|
assert.strictEqual(slugify('UPPER CASE', true), 'UPPER-CASE');
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user