mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
fix: slash command name regex (#8265)
This commit is contained in:
@@ -42,6 +42,8 @@ describe('Slash Commands', () => {
|
|||||||
describe('Assertions tests', () => {
|
describe('Assertions tests', () => {
|
||||||
test('GIVEN valid name THEN does not throw error', () => {
|
test('GIVEN valid name THEN does not throw error', () => {
|
||||||
expect(() => SlashCommandAssertions.validateName('ping')).not.toThrowError();
|
expect(() => SlashCommandAssertions.validateName('ping')).not.toThrowError();
|
||||||
|
expect(() => SlashCommandAssertions.validateName('hello-world_command')).not.toThrowError();
|
||||||
|
expect(() => SlashCommandAssertions.validateName('aˇ㐆1٢〣²अก')).not.toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GIVEN invalid name THEN throw error', () => {
|
test('GIVEN invalid name THEN throw error', () => {
|
||||||
@@ -51,7 +53,10 @@ describe('Slash Commands', () => {
|
|||||||
expect(() => SlashCommandAssertions.validateName('')).toThrowError();
|
expect(() => SlashCommandAssertions.validateName('')).toThrowError();
|
||||||
|
|
||||||
// Invalid characters used
|
// Invalid characters used
|
||||||
|
expect(() => SlashCommandAssertions.validateName('ABC')).toThrowError();
|
||||||
expect(() => SlashCommandAssertions.validateName('ABC123$%^&')).toThrowError();
|
expect(() => SlashCommandAssertions.validateName('ABC123$%^&')).toThrowError();
|
||||||
|
expect(() => SlashCommandAssertions.validateName('help ping')).toThrowError();
|
||||||
|
expect(() => SlashCommandAssertions.validateName('🦦')).toThrowError();
|
||||||
|
|
||||||
// Too long of a name
|
// Too long of a name
|
||||||
expect(() =>
|
expect(() =>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { isValidationEnabled } from '../../util/validation';
|
|||||||
const namePredicate = s.string
|
const namePredicate = s.string
|
||||||
.lengthGreaterThanOrEqual(1)
|
.lengthGreaterThanOrEqual(1)
|
||||||
.lengthLessThanOrEqual(32)
|
.lengthLessThanOrEqual(32)
|
||||||
.regex(/^[\P{Lu}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u)
|
.regex(/^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u)
|
||||||
.setValidationEnabled(isValidationEnabled);
|
.setValidationEnabled(isValidationEnabled);
|
||||||
|
|
||||||
export function validateName(name: unknown): asserts name is string {
|
export function validateName(name: unknown): asserts name is string {
|
||||||
|
|||||||
Reference in New Issue
Block a user