Coder Social home page Coder Social logo

Comments (5)

adrianmiu avatar adrianmiu commented on July 22, 2024

Hi.

Unfortunately this is a bug. I will try to fix it asap but I'm a bit swamped at the moment.
If you have PR i'd be happy to accept it :)

from validation.

pachico avatar pachico commented on July 22, 2024

Not sure when I'll have time to look at it during the next 2 weeks. :(

from validation.

eclipxe13 avatar eclipxe13 commented on July 22, 2024

As far I can see the problem is not inside rules. The problem is inside ValueValidator::validate:

The current logic is:

  1. determine if the rules set contains a Required rule ($isRequired).
  2. if is not required ! $isRequired and value is not set then exit and don't evaluate anything.
  3. evaluate each rule
    1. perform rule validation
    2. exit the loop if $isRequired and the rule fail
  4. return if there were errors

The problem is that in step 3 it is expected that all the rules validate positive. So, for the set of requiredWith & number, the first evaluate to true but the second evaluates to false.

I think I solve this issue by making a two step evaluation:

  1. Evaluate each rule that is an instance of Required.
  2. Exit if is not required ! $isRequired and value is not set.
  3. Evaluate each rule that is a not an instance of Required.
  4. Return if there were errors.

I'm preparing a PR for this... stay tuned.

from validation.

eclipxe13 avatar eclipxe13 commented on July 22, 2024

Final steps of fix are:

  1. Evaluate each rule that is an instance of Required, return false on failure.
  2. Exit if value is not set (required rules has been evaluated previously).
  3. Evaluate each rule that is a not an instance of Required.
  4. Return if there were errors.

PR #44 was created

from validation.

adrianmiu avatar adrianmiu commented on July 22, 2024

@eclipxe13 Thank you for the PR!

from validation.

Related Issues (20)

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.