Skip to content

Commit ee53ef7

Browse files
committed
fix: reset pattern index after testing an input
Otherwise, we flip flop between validations See #1181 (comment)
1 parent cddd038 commit ee53ef7

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

deno/utils/internals.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,14 @@ export type DistributiveOmit<T, K extends DistributiveKeys<T>> =
4040

4141
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
4242

43-
export const urlSafeCharacters = /^[\d%A-Za-z-]+$/g;
43+
const pattern = /^[\d%A-Za-z-]+$/g;
44+
45+
export const urlSafeCharacters = {
46+
test(input: string) {
47+
const result = pattern.test(input);
48+
49+
pattern.lastIndex = 0;
50+
51+
return result;
52+
},
53+
};

tests/v10/routes-escaping.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { strictEqual } from 'node:assert';
2+
import { Routes } from '../../v10';
3+
4+
const expected = '/channels/1320466398597615666/messages/1320622300642545705/reactions/%F0%9F%95%99/@me';
5+
6+
strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', '%F0%9F%95%99'), expected);
7+
strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', '%F0%9F%95%99'), expected);
8+
strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', '%F0%9F%95%99'), expected);
9+
10+
const emoji = '🕙';
11+
12+
strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', emoji), expected);

utils/internals.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,14 @@ export type DistributiveOmit<T, K extends DistributiveKeys<T>> =
4040

4141
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
4242

43-
export const urlSafeCharacters = /^[\d%A-Za-z-]+$/g;
43+
const pattern = /^[\d%A-Za-z-]+$/g;
44+
45+
export const urlSafeCharacters = {
46+
test(input: string) {
47+
const result = pattern.test(input);
48+
49+
pattern.lastIndex = 0;
50+
51+
return result;
52+
},
53+
};

0 commit comments

Comments
 (0)