jhthorsen / json-validator

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

Given a valid JSON string that ends in a newline, the schema() method emits a warning #232

Closed davidcantrell-bb closed 3 years ago

davidcantrell-bb commented 3 years ago

Steps to reproduce the behavior

JSON::Validator->new()->schema(q!{ "type": "object" }
!)

note the newline before the closing quote.

Expected behavior

There should be no warning

Actual behavior

A warning is emitted: Unsuccessful stat on filename containing newline at /blahblah/JSON/Validator.pm line 317.

Suggested fix

Tightly scoped no warnings 'newline';, something like ...


my $loadable = do {
  no warnings 'newline';
  (blessed $source && ($source->can('scheme') || $source->isa('Mojo::File')))
  || -f $source
  || (!ref $source && $source =~ /^\w/);
};
abraxxa commented 3 years ago

I just chased this error message for hours until I looked for open issues, thanks!

DrHyde commented 3 years ago

There, have a trivial fix :-)

jhthorsen commented 3 years ago

This is now fixed in #233.