提交 4162f42f 编写于 作者: P Paul Calabrese 提交者: Kevin Heifner

STAT-273: Fix json parsing issues

(cherry picked from commit 9aa838e9)
上级 aeada7b2
...@@ -96,9 +96,8 @@ namespace fc ...@@ -96,9 +96,8 @@ namespace fc
"Expected '\"' but read '${char}'", "Expected '\"' but read '${char}'",
("char", string(&c, (&c) + 1) ) ); ("char", string(&c, (&c) + 1) ) );
in.get(); in.get();
while( true ) while( !in.eof() )
{ {
switch( c = in.peek() ) switch( c = in.peek() )
{ {
case '\\': case '\\':
...@@ -128,7 +127,7 @@ namespace fc ...@@ -128,7 +127,7 @@ namespace fc
{ {
char c = in.peek(); char c = in.peek();
while( true ) while( !in.eof() )
{ {
switch( c = in.peek() ) switch( c = in.peek() )
{ {
...@@ -359,7 +358,7 @@ namespace fc ...@@ -359,7 +358,7 @@ namespace fc
return variant(); return variant();
if( str == "true" ) if( str == "true" )
return true; return true;
if( str == "false" ) if( str == "false" )
return false; return false;
else else
{ {
...@@ -453,7 +452,7 @@ namespace fc ...@@ -453,7 +452,7 @@ namespace fc
FC_ASSERT( open_object < 100 && open_array < 100, "object graph too deep", ("object depth",open_object)("array depth", open_array) ); FC_ASSERT( open_object < 100 && open_array < 100, "object graph too deep", ("object depth",open_object)("array depth", open_array) );
} }
} }
variant json::from_string( const std::string& utf8_str, parse_type ptype ) variant json::from_string( const std::string& utf8_str, parse_type ptype )
{ try { { try {
check_string_depth( utf8_str ); check_string_depth( utf8_str );
......
...@@ -22,6 +22,26 @@ using namespace std; ...@@ -22,6 +22,26 @@ using namespace std;
BOOST_AUTO_TEST_SUITE(misc_tests) BOOST_AUTO_TEST_SUITE(misc_tests)
/// Test processing of unbalanced strings
BOOST_AUTO_TEST_CASE(json_from_string_test)
{
bool exc_found = false;
try {
auto val = fc::json::from_string("{\"}");
} catch(...) {
exc_found = true;
}
BOOST_CHECK_EQUAL(exc_found, true);
exc_found = false;
try {
auto val = fc::json::from_string("{\"block_num_or_id\":5");
} catch(...) {
exc_found = true;
}
BOOST_CHECK_EQUAL(exc_found, true);
}
/// Test calculation of median values of blockchain operation properties /// Test calculation of median values of blockchain operation properties
BOOST_AUTO_TEST_CASE(median_properties_test) BOOST_AUTO_TEST_CASE(median_properties_test)
{ try { { try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册