Giter VIP home page Giter VIP logo

validation's Introduction

somnambulist-tech

Organization repository for discussions

validation's People

Contributors

ashleyfield avatar dave-redfern avatar developermarius avatar relliv avatar xjuvi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

validation's Issues

Uncaught TypeError: is_uploaded_file() must be of type string

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?

URL validation rule is being executed even not being it isn't required

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: Multiple File input without .* key

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.

Regex pipe validation error

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

Add PHP7.4 support

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

Language change doesn't work

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

Attribute search in multidimensional array

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.

Custom message separator - ':' or '.'?

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', ]);

Params undeclared when using regex

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.

TypeError is thrown if rules like Url,Regex recieves default NULL value

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.