mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Allow strings starting with numbers in alphanumeric string validator (#15425)
This commit is contained in:
committed by
GitHub
parent
ec63a61652
commit
64b3fa3d17
@@ -35,6 +35,8 @@ export const tryToParseString = (value: unknown): string => {
|
|||||||
};
|
};
|
||||||
export const tryToParseAlphanumericString = (value: unknown): string => {
|
export const tryToParseAlphanumericString = (value: unknown): string => {
|
||||||
const parsed = tryToParseString(value);
|
const parsed = tryToParseString(value);
|
||||||
|
// We do not allow special characters, only letters, numbers and underscore
|
||||||
|
// Numbers not allowed as the first character
|
||||||
const regex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
const regex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
||||||
if (!regex.test(parsed)) {
|
if (!regex.test(parsed)) {
|
||||||
throw new ApplicationError('Value is not a valid alphanumeric string', { extra: { value } });
|
throw new ApplicationError('Value is not a valid alphanumeric string', { extra: { value } });
|
||||||
|
|||||||
@@ -3,6 +3,38 @@ import { DateTime, Settings } from 'luxon';
|
|||||||
import { getValueDescription, tryToParseDateTime, validateFieldType } from '@/TypeValidation';
|
import { getValueDescription, tryToParseDateTime, validateFieldType } from '@/TypeValidation';
|
||||||
|
|
||||||
describe('Type Validation', () => {
|
describe('Type Validation', () => {
|
||||||
|
describe('string-alphanumeric', () => {
|
||||||
|
test('should validate and parse alphanumeric strings, not starting with a number', () => {
|
||||||
|
const VALID_STRINGS = ['abc123', 'ABC123', 'abc_123', '_abc123', 'abcABC123_'];
|
||||||
|
VALID_STRINGS.forEach((value) =>
|
||||||
|
expect(validateFieldType('string', value, 'string-alphanumeric')).toEqual({
|
||||||
|
valid: true,
|
||||||
|
newValue: value,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not validate non-alphanumeric strings, or starting with a number', () => {
|
||||||
|
const INVALID_STRINGS = [
|
||||||
|
'abc-123',
|
||||||
|
'abc 123',
|
||||||
|
'abc@123',
|
||||||
|
'abc#123',
|
||||||
|
'abc.123',
|
||||||
|
'abc$123',
|
||||||
|
'abc&123',
|
||||||
|
'abc!123',
|
||||||
|
'abc(123)',
|
||||||
|
'bπc123',
|
||||||
|
'πι',
|
||||||
|
'123abc', // Cannot start with number
|
||||||
|
'456_abc', // Cannot start with number
|
||||||
|
];
|
||||||
|
INVALID_STRINGS.forEach((value) =>
|
||||||
|
expect(validateFieldType('string', value, 'string-alphanumeric').valid).toBe(false),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('Dates', () => {
|
describe('Dates', () => {
|
||||||
test('should validate and cast ISO dates', () => {
|
test('should validate and cast ISO dates', () => {
|
||||||
const VALID_ISO_DATES = [
|
const VALID_ISO_DATES = [
|
||||||
|
|||||||
Reference in New Issue
Block a user