fix: remove bidiControls from notification.bodyShort

This commit is contained in:
Barış Soner Uşaklı
2026-01-06 12:48:09 -05:00
parent 5a031d01e6
commit b0679cadcf
3 changed files with 26 additions and 1 deletions

View File

@@ -300,7 +300,9 @@ const utils = {
const pattern = (tags || ['']).join('|');
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) {
if (typeof tag !== 'string' || !tag.length) {
return '';

View File

@@ -177,6 +177,9 @@ Notifications.create = async function (data) {
if (!result.data) {
return null;
}
if (data.bodyShort) {
data.bodyShort = utils.stripBidiControls(data.bodyShort);
}
await Promise.all([
db.sortedSetAdd('notifications', now, data.nid),
db.setObject(`notifications:${data.nid}`, data),

View File

@@ -44,6 +44,26 @@ describe('Utility Methods', () => {
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) => {
assert.strictEqual(slugify('UPPER CASE', true), 'UPPER-CASE');
done();