mirror of
https://github.com/tiennm99/coolify.git
synced 2026-07-06 05:06:26 +00:00
refactor: consolidate file path validation patterns and support scoped packages
- Extract file path validation regex into ValidationPatterns::FILE_PATH_PATTERN constant - Add filePathRules() and filePathMessages() helper methods for reusable validation - Extend allowed characters from [a-zA-Z0-9._\-/] to [a-zA-Z0-9._\-/~@+] to support: - Scoped npm packages (@org/package) - Language-specific directories (c++, rust+) - Version markers (v1~, build~) - Replace duplicate inline regex patterns across multiple files - Add tests for paths with @ symbol and tilde/plus characters
This commit is contained in:
@@ -17,6 +17,12 @@ class ValidationPatterns
|
||||
*/
|
||||
public const DESCRIPTION_PATTERN = '/^[\p{L}\p{M}\p{N}\s\-_.,!?()\'\"+=*@\/&]+$/u';
|
||||
|
||||
/**
|
||||
* Pattern for file paths (dockerfile location, docker compose location, etc.)
|
||||
* Allows alphanumeric, dots, hyphens, underscores, slashes, @, ~, and +
|
||||
*/
|
||||
public const FILE_PATH_PATTERN = '/^\/[a-zA-Z0-9._\-\/~@+]+$/';
|
||||
|
||||
/**
|
||||
* Get validation rules for name fields
|
||||
*/
|
||||
@@ -81,7 +87,25 @@ class ValidationPatterns
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get validation rules for file path fields (dockerfile location, docker compose location)
|
||||
*/
|
||||
public static function filePathRules(int $maxLength = 255): array
|
||||
{
|
||||
return ['nullable', 'string', 'max:'.$maxLength, 'regex:'.self::FILE_PATH_PATTERN];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validation messages for file path fields
|
||||
*/
|
||||
public static function filePathMessages(string $field = 'dockerfileLocation', string $label = 'Dockerfile'): array
|
||||
{
|
||||
return [
|
||||
"{$field}.regex" => "The {$label} location must be a valid path starting with / and containing only alphanumeric characters, dots, hyphens, underscores, slashes, @, ~, and +.",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get combined validation messages for both name and description fields
|
||||
*/
|
||||
public static function combinedMessages(): array
|
||||
|
||||
Reference in New Issue
Block a user