Skip Menu |

This queue is for tickets about the JSON-Schema CPAN distribution.

Report information
The Basics
Id: 122633
Status: open
Priority: 0/
Queue: JSON-Schema

People
Owner: Nobody in particular
Requestors: RAUNAKK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: Number should accept exponential form as per JSON schema specification
If we do pass floating numbers like 0.000000023, currently it fails $result = $schema4->validate({ test => 0.000000023 }); ok $result->valid, 'number against decimal number with more than 5 decimal places' or map { diag "reason: $_" } $result->errors; Test fails with this reason: not ok 24 - number against decimal number with more than 5 decimal places # Failed test 'number against decimal number with more than 5 decimal places' # at t/05union.t line 181. # reason: $.test: string value found, but a number is required as it converts into 23e-07 Refer https://tools.ietf.org/html/rfc7159#section-6
Subject: numberschema.patch
diff --git a/lib/JSON/Schema/Helper.pm b/lib/JSON/Schema/Helper.pm index 67b659e..3cefc6d 100644 --- a/lib/JSON/Schema/Helper.pm +++ b/lib/JSON/Schema/Helper.pm @@ -489,7 +489,7 @@ sub jsMatchType if (lc $type eq 'number') { - return ($value =~ /^\-?[0-9]*(\.[0-9]*)?$/ and length $value) ? TRUE : FALSE; + return ($value =~ /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/ and length $value) ? TRUE : FALSE; } if (lc $type eq 'integer') diff --git a/t/05union.t b/t/05union.t index 4801e41..ec862c6 100644 --- a/t/05union.t +++ b/t/05union.t @@ -166,4 +166,33 @@ $result = $schema3->validate({ test => undef }); ok $result->valid, 'all types against null' or map { diag "reason: $_" } $result->errors; +my $schema4 = JSON::Schema->new( + { type => 'object' + , additionalProperties => 0 + , properties => + { test => + { type => [ qw/number/ ], required => 1 } + } + } ); + +$result = $schema4->validate({ test => 23 }); +ok $result->valid, 'number against integer' + or map { diag "reason: $_" } $result->errors; + +$result = $schema4->validate({ test => 0.00023 }); +ok $result->valid, 'number against decimal number' + or map { diag "reason: $_" } $result->errors; + +$result = $schema4->validate({ test => 0.000000023 }); +ok $result->valid, 'number against decimal number with more than 5 decimal places' + or map { diag "reason: $_" } $result->errors; + +$result = $schema4->validate({ test => -0.000000023 }); +ok $result->valid, 'number against negative number with more than 5 decimal places' + or map { diag "reason: $_" } $result->errors; + +$result = $schema4->validate({ test => 23e-05 }); +ok $result->valid, 'number against exponential number' + or map { diag "reason: $_" } $result->errors; + done_testing;
On Fri Jul 28 23:41:12 2017, RAUNAKK wrote: Show quoted text
> If we do pass floating numbers like 0.000000023, currently it fails > > $result = $schema4->validate({ test => 0.000000023 }); > ok $result->valid, 'number against decimal number with more than 5 > decimal places' > or map { diag "reason: $_" } $result->errors; > > > Test fails with this reason: > > not ok 24 - number against decimal number with more than 5 decimal > places > # Failed test 'number against decimal number with more than 5 > decimal places' > # at t/05union.t line 181. > # reason: $.test: string value found, but a number is required > > as it converts into 23e-07 > > Refer https://tools.ietf.org/html/rfc7159#section-6
Forgot add PR, here is the PR url https://bitbucket.org/tobyink/p5-json-schema/pull-requests/3/
Thanks for the PR. I took on maint in hopes to upgrade to draft4, but I couldn't even make a new build because the build process is convoluted. Tobyink has stated that he won't make updates till JSON Schema is out of draft status. I suggest you try JSON::Schema::AsType. On Sat Jul 29 00:07:52 2017, RAUNAKK wrote: Show quoted text
> On Fri Jul 28 23:41:12 2017, RAUNAKK wrote:
> > If we do pass floating numbers like 0.000000023, currently it fails > > > > $result = $schema4->validate({ test => 0.000000023 }); > > ok $result->valid, 'number against decimal number with more than 5 > > decimal places' > > or map { diag "reason: $_" } $result->errors; > > > > > > Test fails with this reason: > > > > not ok 24 - number against decimal number with more than 5 decimal > > places > > # Failed test 'number against decimal number with more than 5 > > decimal places' > > # at t/05union.t line 181. > > # reason: $.test: string value found, but a number is required > > > > as it converts into 23e-07 > > > > Refer https://tools.ietf.org/html/rfc7159#section-6
> > Forgot add PR, here is the PR url https://bitbucket.org/tobyink/p5- > json-schema/pull-requests/3/