fix: reset pattern index after testing an input

Otherwise, we flip flop between validations
See https://github.com/discordjs/discord-api-types/issues/1181#issuecomment-2558971449
This commit is contained in:
Vlad Frangu
2024-12-23 08:17:44 +02:00
parent cddd038a8b
commit ee53ef7306
3 changed files with 34 additions and 2 deletions

View File

@@ -40,4 +40,14 @@ export type DistributiveOmit<T, K extends DistributiveKeys<T>> =
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
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;
},
};

View File

@@ -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);

View File

@@ -40,4 +40,14 @@ export type DistributiveOmit<T, K extends DistributiveKeys<T>> =
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
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;
},
};