Code Monkey home page Code Monkey logo

Comments (3)

mchiocca avatar mchiocca commented on July 28, 2024

The correct check for "integer" types is definitely is_int($value) without the ctype_digit($value) which returns true for strings (e.g. "12"). Strings are not valid integers according to the latest draft v4.

The "number" type also has the same problem as "integer". The code uses is_numeric($value) which returns true for strings (e.g. "12.5"). So a better check would simple reject strings altogether.

Also notable is that there are two constants declared in Constraints/Constraint.php.

const CHECK_MODE_NORMAL = 1;
const CHECK_MODE_TYPE_CAST = 2;

I searched throughout the code and found that these constants are never anywhere used except in one of the unit test files, PhpTypeCastModeTest.php. These tests are in fact erroneous.

Schema validation doesn't support casting so you can never pass a string for "integer", "number", or "boolean" types. Draft v3 and v4 compliant validation should reject strings for these types altogether.

I believe that the above constants can be removed from the code entirely and the unit test file deleted. Any new type tests can be added to existing unit test files, such as NumberAndIntegerTypesTest.php.

from json-schema.

mchiocca avatar mchiocca commented on July 28, 2024

This issue has been fixed by merging #41 into master.

from json-schema.

justinrainbow avatar justinrainbow commented on July 28, 2024

Thanks for adding the fix for this @mchiocca.

from json-schema.

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.