fix: route escaping round three

This commit is contained in:
Vlad Frangu
2025-02-02 02:22:59 +02:00
parent 2023a0ab2a
commit d5cdb37a8f
3 changed files with 23 additions and 7 deletions

View File

@@ -40,7 +40,8 @@ export type DistributiveOmit<T, K extends DistributiveKeys<T>> =
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
const pattern = /^[\d%A-Za-z-]+$/g;
// eslint-disable-next-line unicorn/better-regex
const pattern = /^[\d%A-Za-z-_]+$/g;
export const urlSafeCharacters = {
test(input: string) {

View File

@@ -1,12 +1,26 @@
import { strictEqual } from 'node:assert';
import { Routes } from '../../v10';
const expected = '/channels/1320466398597615666/messages/1320622300642545705/reactions/%F0%9F%95%99/@me';
const channelId = '1320466398597615666';
const messageId = '1320622300642545705';
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 expected = `/channels/${channelId}/messages/${messageId}/reactions/%F0%9F%95%99/@me`;
// Run multiple times to ensure that the validation isn't intermittent
strictEqual(Routes.channelMessageOwnReaction(channelId, messageId, '%F0%9F%95%99'), expected);
strictEqual(Routes.channelMessageOwnReaction(channelId, messageId, '%F0%9F%95%99'), expected);
strictEqual(Routes.channelMessageOwnReaction(channelId, messageId, '%F0%9F%95%99'), expected);
// make sure that the emoji is properly encoded
const emoji = '🕙';
strictEqual(Routes.channelMessageOwnReaction('1320466398597615666', '1320622300642545705', emoji), expected);
strictEqual(Routes.channelMessageOwnReaction(channelId, messageId, emoji), expected);
// test custom emojis too
const animated = '1_:1234567890';
const encodedExpected = '1_%3A1234567890';
const expected2 = `/channels/${channelId}/messages/${messageId}/reactions/${encodedExpected}/@me`;
strictEqual(Routes.channelMessageOwnReaction(channelId, messageId, animated), expected2);
strictEqual(Routes.channelMessageOwnReaction(channelId, messageId, encodedExpected), expected2);

View File

@@ -40,7 +40,8 @@ export type DistributiveOmit<T, K extends DistributiveKeys<T>> =
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
const pattern = /^[\d%A-Za-z-]+$/g;
// eslint-disable-next-line unicorn/better-regex
const pattern = /^[\d%A-Za-z-_]+$/g;
export const urlSafeCharacters = {
test(input: string) {