mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
fix(escapeX): emojis with underlines
This commit is contained in:
@@ -185,7 +185,7 @@ function escapeItalic(text) {
|
|||||||
return `\\*${match}`;
|
return `\\*${match}`;
|
||||||
});
|
});
|
||||||
i = 0;
|
i = 0;
|
||||||
return text.replace(/(?<=^|[^_])_([^_]|__|$)/g, (_, match) => {
|
return text.replace(/(?<=^|[^_])(?<!<a?:.+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => {
|
||||||
if (match === '__') return ++i % 2 ? `\\_${match}` : `${match}\\_`;
|
if (match === '__') return ++i % 2 ? `\\_${match}` : `${match}\\_`;
|
||||||
return `\\_${match}`;
|
return `\\_${match}`;
|
||||||
});
|
});
|
||||||
@@ -211,7 +211,7 @@ function escapeBold(text) {
|
|||||||
*/
|
*/
|
||||||
function escapeUnderline(text) {
|
function escapeUnderline(text) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
return text.replace(/__(_)?/g, (_, match) => {
|
return text.replace(/(?<!<a?:.+)__(_)?(?!:\d+>)/g, (_, match) => {
|
||||||
if (match) return ++i % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
|
if (match) return ++i % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
|
||||||
return '\\_\\_';
|
return '\\_\\_';
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -58,6 +58,13 @@ describe('escapeItalic', () => {
|
|||||||
test('basic (*)', () => {
|
test('basic (*)', () => {
|
||||||
expect(Util.escapeItalic('*test*')).toEqual('\\*test\\*');
|
expect(Util.escapeItalic('*test*')).toEqual('\\*test\\*');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emoji', () => {
|
||||||
|
const testOne = 'This is a test with _emojis_ <:Frost_ed_Wreath:1053399941210443826> and **bold text**.';
|
||||||
|
expect(Util.escapeItalic(testOne)).toEqual(
|
||||||
|
'This is a test with \\_emojis\\_ <:Frost_ed_Wreath:1053399941210443826> and **bold text**.',
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('escapeUnderline', () => {
|
describe('escapeUnderline', () => {
|
||||||
@@ -70,6 +77,13 @@ describe('escapeUnderline', () => {
|
|||||||
test('basic', () => {
|
test('basic', () => {
|
||||||
expect(Util.escapeUnderline('__test__')).toEqual('\\_\\_test\\_\\_');
|
expect(Util.escapeUnderline('__test__')).toEqual('\\_\\_test\\_\\_');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('emoji', () => {
|
||||||
|
const testTwo = 'This is a test with __emojis__ <:Frost__ed__Wreath:1053399939654352978> and **bold text**.';
|
||||||
|
expect(Util.escapeUnderline(testTwo)).toBe(
|
||||||
|
'This is a test with \\_\\_emojis\\_\\_ <:Frost__ed__Wreath:1053399939654352978> and **bold text**.',
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('escapeStrikethrough', () => {
|
describe('escapeStrikethrough', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user