jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

make JSON::Validator::Util::is_bool return true when passed perl v5.36+ builtin booleans #275

Open akarelas opened 1 month ago

akarelas commented 1 month ago

Summary

This PR allows newer Perls' (v5.36+) builtin core booleans to be validated as booleans. It's quite a necessary change to make, as when you include the line use v5.40 in your code file, you may not replace the meaning of true and false from perl's core booleans just by writing use Mojo::JSON 'true', 'false';. Therefore, it seems, core booleans need to be considered valid by all CPAN modules.

I did it by modifying slightly the JSON::Validator::Util::is_bool function, inspired by how JSON::PP recently achieved the same effect.

Motivation

My motivation was to resolve this bug of Mojolicious::Plugin::OpenAPI: https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/252

Tried my solution

I tested my modifications on a test Mojolicious website that uses Mojolicious::Plugin::OpenAPI, using both perl v5.34 (that doesn't have the builtin booleans) and perl v5.40 (that does), and the site works in both these cases.

I forgot to run prove -vl on it, or write tests with core booleans that will run only on perl v5.40. I will do so later today or tomorrow.

References

jhthorsen commented 12 hours ago

I can't take the change, since too many tests fail.

akarelas commented 12 hours ago

We need to find out why those tests fail. Would they fail on any PR (even adding a blank line in a file)? If so, it's really a problem not to be attributed to me. If not, then I need to look at it.