File tree 2 files changed +48
-3
lines changed
2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ namespace jse
367
367
{
368
368
assert (rule.at (" type" ) == " float" );
369
369
370
- if (!input.is_number ())
370
+ if (!input.is_number () && !input. is_null () )
371
371
return false ;
372
372
373
373
if (rule.contains (" min" ) && input < rule[" min" ])
@@ -383,7 +383,7 @@ namespace jse
383
383
{
384
384
assert (rule.at (" type" ) == " int" );
385
385
386
- if (!input.is_number_integer ())
386
+ if (!input.is_number_integer () && !input. is_null () )
387
387
return false ;
388
388
389
389
if (rule.contains (" min" ) && input < rule[" min" ])
Original file line number Diff line number Diff line change @@ -250,7 +250,6 @@ TEST_CASE("include_rule", "[validator]")
250
250
REQUIRE (new_rules == matching);
251
251
}
252
252
253
-
254
253
TEST_CASE (" file_01" , " [validator]" )
255
254
{
256
255
std::ifstream ifs1 (root_path + " /input_01.json" );
@@ -611,3 +610,49 @@ TEST_CASE("polymorphism", "[inject]")
611
610
INFO (return_json);
612
611
REQUIRE (return_json == output);
613
612
}
613
+
614
+ TEST_CASE (" null_as_nan" , " [validator][inject]" )
615
+ {
616
+ nlohmann::json rules = R"(
617
+ [
618
+ {
619
+ "pointer": "/",
620
+ "type": "object",
621
+ "required": ["f1"],
622
+ "optional": ["f2"]
623
+ },
624
+ {
625
+ "pointer": "/f1",
626
+ "type": "float"
627
+ },
628
+ {
629
+ "pointer": "/f2",
630
+ "type": "int",
631
+ "default": null
632
+ }
633
+ ]
634
+ )" _json;
635
+
636
+ nlohmann::json input = R"(
637
+ {
638
+ "f1": null,
639
+ "f2": null
640
+ }
641
+ )" _json;
642
+
643
+ JSE jse;
644
+ jse.strict = true ;
645
+
646
+ bool r = jse.verify_json (input, rules);
647
+ REQUIRE (r);
648
+
649
+ input.erase (" f2" );
650
+ r = jse.verify_json (input, rules);
651
+ REQUIRE (r);
652
+
653
+ const json return_json = jse.inject_defaults (input, rules);
654
+ CHECK (return_json[" f1" ].is_null ());
655
+ CHECK (return_json[" f2" ].is_null ());
656
+
657
+ input[" f2" ] = std::nan (" " );
658
+ }
You can’t perform that action at this time.
0 commit comments