mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Move interrelated entities to @n8n/db (#15050)
This commit is contained in:
27
packages/@n8n/db/src/utils/validators/no-url.validator.ts
Normal file
27
packages/@n8n/db/src/utils/validators/no-url.validator.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
|
||||
import { registerDecorator, ValidatorConstraint } from 'class-validator';
|
||||
|
||||
const URL_REGEX = /^(https?:\/\/|www\.)|(\.[\p{L}\d-]+)/iu;
|
||||
|
||||
@ValidatorConstraint({ name: 'NoUrl', async: false })
|
||||
class NoUrlConstraint implements ValidatorConstraintInterface {
|
||||
validate(value: string) {
|
||||
return !URL_REGEX.test(value);
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return 'Potentially malicious string';
|
||||
}
|
||||
}
|
||||
|
||||
export function NoUrl(options?: ValidationOptions) {
|
||||
return function (object: object, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'NoUrl',
|
||||
target: object.constructor,
|
||||
propertyName,
|
||||
options,
|
||||
validator: NoUrlConstraint,
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user