Skip to content

Commit

Permalink
Rename fc json flag 'strict_validation' to 'full_json_validation'
Browse files Browse the repository at this point in the history
  • Loading branch information
asuch authored and vogel76 committed Nov 2, 2023
1 parent 936247b commit fc20ed0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions libraries/fc/include/fc/io/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ namespace fc

static variant from_stream( buffered_istream& in, parse_type ptype = legacy_parser, uint32_t depth = 0 );

static variant from_string( const string& utf8_str, const bool strict_validation = true, parse_type ptype = legacy_parser, uint32_t depth = 0 );
static variant from_string( const string& utf8_str, const bool full_json_validation = true, parse_type ptype = legacy_parser, uint32_t depth = 0 );
static variant fast_from_string( const string& utf8_str );
static variants variants_from_string( const string& utf8_str, parse_type ptype = legacy_parser, uint32_t depth = 0 );
static string to_string( const variant& v, output_formatting format = stringify_large_ints_and_doubles );
static string to_pretty_string( const variant& v, output_formatting format = stringify_large_ints_and_doubles );

static bool is_valid( const std::string& json_str, const bool strict_validation = true, parse_type ptype = legacy_parser, uint32_t depth = 0 );
static bool is_valid( const std::string& json_str, const bool full_json_validation = true, parse_type ptype = legacy_parser, uint32_t depth = 0 );
static bool fast_is_valid( const std::string& json_str );

template<typename T>
Expand Down
42 changes: 21 additions & 21 deletions libraries/fc/src/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
namespace fc
{
// forward declarations of provided functions
template<typename T, json::parse_type parser_type> variant variant_from_stream( T& in, const bool strict_validation, uint32_t depth = 0 );
template<typename T, json::parse_type parser_type> variant variant_from_stream( T& in, const bool full_json_validation, uint32_t depth = 0 );
template<typename T> char parseEscape( T& in, uint32_t depth = 0 );
template<typename T> fc::string stringFromStream( T& in, uint32_t depth = 0 );
template<typename T> bool skip_white_space( T& in, uint32_t depth = 0 );
template<typename T> fc::string stringFromToken( T& in, uint32_t depth = 0 );
template<typename T, json::parse_type parser_type> variant_object objectFromStream( T& in, const bool strict_validation, uint32_t depth = 0 );
template<typename T, json::parse_type parser_type> variants arrayFromStream( T& in, const bool strict_validation, uint32_t depth = 0 );
template<typename T, json::parse_type parser_type> variant_object objectFromStream( T& in, const bool full_json_validation, uint32_t depth = 0 );
template<typename T, json::parse_type parser_type> variants arrayFromStream( T& in, const bool full_json_validation, uint32_t depth = 0 );
template<typename T, json::parse_type parser_type> variant number_from_stream( T& in, uint32_t depth = 0 );
template<typename T> variant token_from_stream( T& in, uint32_t depth = 0 );
template<typename T> void escape_string( const string& str, T& os, uint32_t depth = 0 );
Expand Down Expand Up @@ -216,7 +216,7 @@ namespace fc
}

template<typename T, json::parse_type parser_type>
variant_object objectFromStream( T& in, const bool strict_validation, uint32_t depth )
variant_object objectFromStream( T& in, const bool full_json_validation, uint32_t depth )
{
depth++;
FC_ASSERT( depth <= JSON_MAX_RECURSION_DEPTH );
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace fc
("key", key) );
}
in.get();
auto val = variant_from_stream<T, parser_type>( in, strict_validation, depth );
auto val = variant_from_stream<T, parser_type>( in, full_json_validation, depth );

obj(std::move(key),std::move(val));
skip_white_space( in, depth );
Expand All @@ -269,7 +269,7 @@ namespace fc
}

template<typename T, json::parse_type parser_type>
variants arrayFromStream( T& in, const bool strict_validation, uint32_t depth )
variants arrayFromStream( T& in, const bool full_json_validation, uint32_t depth )
{
depth++;
FC_ASSERT( depth <= JSON_MAX_RECURSION_DEPTH );
Expand Down Expand Up @@ -301,12 +301,12 @@ namespace fc
if (!expecting_new_element)
FC_THROW_EXCEPTION( parse_error_exception, "Missing ',' after object in json array.");

ar.push_back( variant_from_stream<T, parser_type>( in, strict_validation, depth ) );
ar.push_back( variant_from_stream<T, parser_type>( in, full_json_validation, depth ) );
expecting_new_element = false;
skip_white_space( in, depth );
}

if (strict_validation && expecting_new_element && !ar.empty())
if (full_json_validation && expecting_new_element && !ar.empty())
FC_THROW_EXCEPTION( parse_error_exception, "Detected ',' after last array object. Expected ']'");

in.get();
Expand Down Expand Up @@ -455,7 +455,7 @@ namespace fc


template<typename T, json::parse_type parser_type>
variant variant_from_stream( T& in, const bool strict_validation, uint32_t depth )
variant variant_from_stream( T& in, const bool full_json_validation, uint32_t depth )
{
depth++;
FC_ASSERT( depth <= JSON_MAX_RECURSION_DEPTH );
Expand All @@ -475,9 +475,9 @@ namespace fc
case '"':
return stringFromStream( in, depth );
case '{':
return objectFromStream<T, parser_type>( in, strict_validation, depth );
return objectFromStream<T, parser_type>( in, full_json_validation, depth );
case '[':
return arrayFromStream<T, parser_type>( in, strict_validation, depth );
return arrayFromStream<T, parser_type>( in, full_json_validation, depth );
case '-':
case '.':
case '0':
Expand Down Expand Up @@ -528,7 +528,7 @@ namespace fc
}
}

variant json::from_string( const std::string& utf8_str, const bool strict_validation, parse_type ptype, uint32_t depth )
variant json::from_string( const std::string& utf8_str, const bool full_json_validation, parse_type ptype, uint32_t depth )
{ try {
depth++;
FC_ASSERT( depth <= JSON_MAX_RECURSION_DEPTH );
Expand All @@ -539,9 +539,9 @@ namespace fc
switch( ptype )
{
case legacy_parser:
return variant_from_stream<fc::stringstream, legacy_parser>( in, strict_validation, depth );
return variant_from_stream<fc::stringstream, legacy_parser>( in, full_json_validation, depth );
case legacy_parser_with_string_doubles:
return variant_from_stream<fc::stringstream, legacy_parser_with_string_doubles>( in, strict_validation, depth );
return variant_from_stream<fc::stringstream, legacy_parser_with_string_doubles>( in, full_json_validation, depth );
case strict_parser:
return json_relaxed::variant_from_stream<fc::stringstream, true>( in, depth );
case relaxed_parser:
Expand Down Expand Up @@ -882,9 +882,9 @@ namespace fc
switch( ptype )
{
case legacy_parser:
return variant_from_stream<boost::filesystem::ifstream, legacy_parser>( bi, true /* strict_validation*/, depth );
return variant_from_stream<boost::filesystem::ifstream, legacy_parser>( bi, true /* full_json_validation*/, depth );
case legacy_parser_with_string_doubles:
return variant_from_stream<boost::filesystem::ifstream, legacy_parser_with_string_doubles>( bi, true /* strict_validation*/, depth );
return variant_from_stream<boost::filesystem::ifstream, legacy_parser_with_string_doubles>( bi, true /* full_json_validation*/, depth );
case strict_parser:
return json_relaxed::variant_from_stream<boost::filesystem::ifstream, true>( bi, depth );
case relaxed_parser:
Expand All @@ -900,9 +900,9 @@ namespace fc
switch( ptype )
{
case legacy_parser:
return variant_from_stream<fc::buffered_istream, legacy_parser>( in, true /* strict_validation*/, depth );
return variant_from_stream<fc::buffered_istream, legacy_parser>( in, true /* full_json_validation*/, depth );
case legacy_parser_with_string_doubles:
return variant_from_stream<fc::buffered_istream, legacy_parser_with_string_doubles>( in, true /* strict_validation*/, depth );
return variant_from_stream<fc::buffered_istream, legacy_parser_with_string_doubles>( in, true /* full_json_validation*/, depth );
case strict_parser:
return json_relaxed::variant_from_stream<buffered_istream, true>( in, depth );
case relaxed_parser:
Expand All @@ -928,17 +928,17 @@ namespace fc
return out;
}

bool json::is_valid( const std::string& utf8_str, const bool strict_validation, parse_type ptype, uint32_t depth )
bool json::is_valid( const std::string& utf8_str, const bool full_json_validation, parse_type ptype, uint32_t depth )
{
if( utf8_str.size() == 0 ) return false;
fc::stringstream in( utf8_str );
switch( ptype )
{
case legacy_parser:
variant_from_stream<fc::stringstream, legacy_parser>( in, strict_validation, depth );
variant_from_stream<fc::stringstream, legacy_parser>( in, full_json_validation, depth );
break;
case legacy_parser_with_string_doubles:
variant_from_stream<fc::stringstream, legacy_parser_with_string_doubles>( in, strict_validation, depth );
variant_from_stream<fc::stringstream, legacy_parser_with_string_doubles>( in, full_json_validation, depth );
break;
case strict_parser:
json_relaxed::variant_from_stream<fc::stringstream, true>( in, depth );
Expand Down
2 changes: 1 addition & 1 deletion libraries/protocol/hive_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace hive { namespace protocol {
if (!fc::json::fast_is_valid(json))
{
FC_ASSERT(fc::is_utf8(json), "JSON not formatted in UTF8");
FC_ASSERT(fc::json::is_valid(json, false /* strict_validation */), "JSON is not valid JSON");
FC_ASSERT(fc::json::is_valid(json, false /* full_json_validation */), "JSON is not valid JSON");
}
}
}
Expand Down

0 comments on commit fc20ed0

Please sign in to comment.