diff --git a/deno/utils/internals.ts b/deno/utils/internals.ts index 58a00ec2..2aa42506 100644 --- a/deno/utils/internals.ts +++ b/deno/utils/internals.ts @@ -40,4 +40,14 @@ export type DistributiveOmit> = type Omit_ = Omit>; -export const urlSafeCharacters = /^[\d%A-Za-z-]+$/g; +const pattern = /^[\d%A-Za-z-]+$/g; + +export const urlSafeCharacters = { + test(input: string) { + const result = pattern.test(input); + + pattern.lastIndex = 0; + + return result; + }, +}; diff --git a/tests/v10/routes-escaping.ts b/tests/v10/routes-escaping.ts new file mode 100644 index 00000000..a38a216b --- /dev/null +++ b/tests/v10/routes-escaping.ts @@ -0,0 +1,12 @@ +import { strictEqual } from 'node:assert'; +import { Routes } from '../../v10'; + +const expected = '/channels/1320466398597615666/messages/1320622300642545705/reactions/%F0%9F%95%99/@me'; + +strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', '%F0%9F%95%99'), expected); +strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', '%F0%9F%95%99'), expected); +strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', '%F0%9F%95%99'), expected); + +const emoji = '🕙'; + +strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', emoji), expected); diff --git a/utils/internals.ts b/utils/internals.ts index 58a00ec2..2aa42506 100644 --- a/utils/internals.ts +++ b/utils/internals.ts @@ -40,4 +40,14 @@ export type DistributiveOmit> = type Omit_ = Omit>; -export const urlSafeCharacters = /^[\d%A-Za-z-]+$/g; +const pattern = /^[\d%A-Za-z-]+$/g; + +export const urlSafeCharacters = { + test(input: string) { + const result = pattern.test(input); + + pattern.lastIndex = 0; + + return result; + }, +};