Organization repository for discussions
somnambulist-tech / validation Goto Github PK
View Code? Open in Web Editor NEWA re-write of rakit/validation, a standalone validation library inspired by Laravel Validation
License: MIT License
A re-write of rakit/validation, a standalone validation library inspired by Laravel Validation
License: MIT License
When using a file input with the 'multiple' attribute, you must add a validation rule with the dot syntax e.g. photos.*
or it throws an error if one or more files is attached:
Uncaught TypeError: is_uploaded_file(): Argument #1 ($filename) must be of type string, array given in .../somnambulist/validation/src/Rules/Behaviours/CanValidateFiles.php:11
I assume this is expected behavior, but the uncaught error should probably return an exception.
In addition, when requiring a file to be attached to a multiple-file input, it does not throw a validation error if no file is attached:
<input type="file" name="photos" multiple accept=".jpg,.jpeg" />
// expected behavior is to throw validation error when no file is attached:
$validation = [
'photos.*' => 'required|uploaded_file:0,1M,jpeg',
];
Am I interpreting or writing the rule wrong, or am I correct in that this is a bug?
The URL validation rule is being executed even not being it isn't required. This way, when not sending the 'hyperlink' key, there ends up being an error in the validation of the library's schema due to at null value.
To "resolve" this, I inform you that the value can be 'nullable', but the other rules don't require this.
Example:
$data = [
"alt" => "Alt",
"main" => true
];
$rules = [
"alt" => "required|string",
"hyperlink" => "url",
"main" => "required|boolean",
];
When executing, this throws the exception:
Uncaught TypeError: Somnambulist\Components\Validation\Rules\Url::validateCommonScheme(): Argument #1 ($value) must be of type string, null given, called in .../vendor/somnambulist/validation/src/Rules/Url.php on line 38 and defined in .../vendor/somnambulist/validation/src/Rules/Url.php:53
Uncaught RuntimeException: Attribute "file_upload" has multiple files, use "file_upload.*" as the attribute key in...
somnambulist/validation/src/Rules/Behaviours/CanValidateFiles.php on line 20
I though I would let you know this is not throwing a clean exception like other misconfigured fields do.
Thank you.
Hi,
a pipe as or in a regular expression is recognized as a new validation rule.
I have replaced the preg_split in resolveRules. Maybe there is a nicer solution.
if (is_string($rules)) {
preg_match('/(?=[^|])(?:[^|]*\/[^)]+\/)*[^|]*/', $rules, $rules) ;
}
Eric
Hello, is it possible for PHP7.4 support to be added... it's an awesome library, and i have a legacy code which still uses php7.4 and i'd really love if we had a 7.4 support
Hi there,
i tried to use the german language template, but i can't use it. Everytime i get the error
"No message was found for the language "de" and any of: "inputUserEmail:email", "inputUserEmail", "rule.email""
I tried both methods, set the language on factory or validator like the docu:
$factory = new Factory(); $factory->messages()->default('de');
and
$validation = $factory->validate($inputs, $rules); $validation->setLanguage('de')->validate();
Where is my mistake? Or is there a bug? I'm unsure. But the only way where language files were loaded is on initialisation of the factory. After that i can set other languages but there is no loading of the file?
Kind regards
When using the required_if validation rule on a multidimensional array, the parameter is not found because the search is done considering the complete array, instead of the specific item.
Example:
$data = [
[
"alt" => "Alt",
"hyperlink" => "https://google.com",
"main" => true
]
];
$rules = [
"*.alt" => "required|string",
"*.hyperlink" => "url",
"*.main" => "boolean",
"*.title" => "required_if:main,true|string",
];
In this way, even passing the main attribute, the title attribute doesn't become required.
hi,
ran into an issue today
reproduction: https://phpsandbox.io/n/9ld9z#index.php
'required|array' for [] should pass unless I'm missing something
'string' for [] should fail, same as above
empty arrays passed in data are treated as missing instead of an array
It looks like custom message key separator is ':'
class Validation { private AttributeBag $attributes; ... private string $separator = ':'; ... protected function resolveMessage(Attribute $attribute, Rule $rule, mixed $value): ErrorMessage { ... $messageKeys = [ $attributeKey . $this->separator . $ruleName, $attributeKey, $message->key(), ];
And doc uses '.'
$factory->messages()->add('es', [ 'rule.required' => 'Se requiere :attribute', ]);
public function check(mixed $value): bool
{
if (!is_string($value) && !is_numeric($value)) {
return false;
}
return preg_match('/^[\pL\pM\pN]+$/u', $value) > 0;
}
Kind of logical error here
If statement allowes string&integer types but preg_match 2-nd param is a string only
If you use for example:
"password": "required|between:8,16|regex:/^[\\da-zA-Z!$%+.]+$/"
Parameters like ":min" and ":max" are undeclared if the string is between 8-16 characters. The problem is that the "regex" validation could fail while "between" parameter is fine. If that happens, you will have a wrong response message with missing (e.g min/max) variables.
Custom response message:
Your password must have between :min and :max characters and only [! $ % + .] as special characters.
How it should look like:
Your password must have between 8 and 16 characters and only [! $ % + .] as special characters.
As you can see, instead of showing the parameter values, the key will be displayed in the response. If your password is not between 8-16 characters, the response is correct, showing the actual values instead of the keys. This issue was still there with rakit validatior.
Somnambulist\Components\Validation\Rules\Url::validateCommonScheme(): Argument #1 ($value) must be of type string, null given, called in .../vendor/somnambulist/validation/src/Rules/Url.php on line 32
So it's impossible to use them as is in cases when validated values are optional
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.