mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
fix(escape*): dont escape urls (#9958)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,13 @@ import {
|
|||||||
const testString = "`_Behold!_`\n||___~~***```js\n`use strict`;\nrequire('discord.js');```***~~___||";
|
const testString = "`_Behold!_`\n||___~~***```js\n`use strict`;\nrequire('discord.js');```***~~___||";
|
||||||
const testStringForums =
|
const testStringForums =
|
||||||
'# Title\n## Subtitle\n### Subsubtitle\n- Bullet list\n - # Title with bullet\n * Subbullet\n1. Number list\n 1. Sub number list';
|
'# Title\n## Subtitle\n### Subsubtitle\n- Bullet list\n - # Title with bullet\n * Subbullet\n1. Number list\n 1. Sub number list';
|
||||||
|
const testURLs = [
|
||||||
|
'https://example.com/name_wow',
|
||||||
|
'https://example.com/name__wow',
|
||||||
|
'https://example.com/name_with_underscores',
|
||||||
|
'https://example.com/name__with__underscores',
|
||||||
|
'https://example.com/name_with_underscores_and__double__underscores',
|
||||||
|
];
|
||||||
|
|
||||||
describe('Markdown escapers', () => {
|
describe('Markdown escapers', () => {
|
||||||
describe('escapeCodeblock', () => {
|
describe('escapeCodeblock', () => {
|
||||||
@@ -76,6 +83,10 @@ describe('Markdown escapers', () => {
|
|||||||
'This is a test with \\_emojis\\_ <:Frost_ed_Wreath:1053399941210443826> and **bold text**.',
|
'This is a test with \\_emojis\\_ <:Frost_ed_Wreath:1053399941210443826> and **bold text**.',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('url', () => {
|
||||||
|
for (const url of testURLs) expect(escapeItalic(url)).toBe(url);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('escapeUnderline', () => {
|
describe('escapeUnderline', () => {
|
||||||
@@ -95,6 +106,10 @@ describe('Markdown escapers', () => {
|
|||||||
'This is a test with \\_\\_emojis\\_\\_ <:Frost__ed__Wreath:1053399939654352978> and **bold text**.',
|
'This is a test with \\_\\_emojis\\_\\_ <:Frost__ed__Wreath:1053399939654352978> and **bold text**.',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('url', () => {
|
||||||
|
for (const url of testURLs) expect(escapeUnderline(url)).toBe(url);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('escapeStrikethrough', () => {
|
describe('escapeStrikethrough', () => {
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ export function escapeItalic(text: string): string {
|
|||||||
return `\\*${match}`;
|
return `\\*${match}`;
|
||||||
});
|
});
|
||||||
idx = 0;
|
idx = 0;
|
||||||
return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => {
|
return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+|https?:\/\/\S+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => {
|
||||||
if (match === '__') return ++idx % 2 ? `\\_${match}` : `${match}\\_`;
|
if (match === '__') return ++idx % 2 ? `\\_${match}` : `${match}\\_`;
|
||||||
return `\\_${match}`;
|
return `\\_${match}`;
|
||||||
});
|
});
|
||||||
@@ -243,7 +243,7 @@ export function escapeBold(text: string): string {
|
|||||||
*/
|
*/
|
||||||
export function escapeUnderline(text: string): string {
|
export function escapeUnderline(text: string): string {
|
||||||
let idx = 0;
|
let idx = 0;
|
||||||
return text.replaceAll(/(?<!<a?:.+)__(_)?(?!:\d+>)/g, (_, match) => {
|
return text.replaceAll(/(?<!<a?:.+|https?:\/\/\S+)__(_)?(?!:\d+>)/g, (_, match) => {
|
||||||
if (match) return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
|
if (match) return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`;
|
||||||
return '\\_\\_';
|
return '\\_\\_';
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user