File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ namespace jse
367367 {
368368 assert (rule.at (" type" ) == " float" );
369369
370- if (!input.is_number ())
370+ if (!input.is_number () && !input. is_null () )
371371 return false ;
372372
373373 if (rule.contains (" min" ) && input < rule[" min" ])
@@ -383,7 +383,7 @@ namespace jse
383383 {
384384 assert (rule.at (" type" ) == " int" );
385385
386- if (!input.is_number_integer ())
386+ if (!input.is_number_integer () && !input. is_null () )
387387 return false ;
388388
389389 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]")
250250 REQUIRE (new_rules == matching);
251251}
252252
253-
254253TEST_CASE (" file_01" , " [validator]" )
255254{
256255 std::ifstream ifs1 (root_path + " /input_01.json" );
@@ -611,3 +610,49 @@ TEST_CASE("polymorphism", "[inject]")
611610 INFO (return_json);
612611 REQUIRE (return_json == output);
613612}
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