mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-02 00:15:50 +00:00
Handle empty strings in Json::Value::empty()
This commit is contained in:
committed by
Nik Bougalis
parent
e4f585b7fe
commit
a5a9242f4e
@@ -825,10 +825,15 @@ Value::size () const
|
||||
bool
|
||||
Value::empty () const
|
||||
{
|
||||
if ( isNull () || isArray () || isObject () )
|
||||
return size () == 0u;
|
||||
else
|
||||
return false;
|
||||
if (isNull ())
|
||||
return true;
|
||||
|
||||
if (isString ()) {
|
||||
auto s = asCString();
|
||||
return !(s && strlen(s));
|
||||
}
|
||||
|
||||
return (isArray () || isObject ()) && ! size ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,29 @@ namespace ripple {
|
||||
class json_value_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void test_empty()
|
||||
{
|
||||
expect (Json::Value().empty());
|
||||
|
||||
expect (Json::Value("").empty());
|
||||
|
||||
expect (! Json::Value("empty").empty());
|
||||
expect (! Json::Value(false).empty());
|
||||
expect (! Json::Value(true).empty());
|
||||
expect (! Json::Value(0).empty());
|
||||
expect (! Json::Value(1).empty());
|
||||
|
||||
Json::Value array (Json::arrayValue);
|
||||
expect (array.empty());
|
||||
array.append(0);
|
||||
expect (!array.empty());
|
||||
|
||||
Json::Value object (Json::objectValue);
|
||||
expect (object.empty());
|
||||
object[""] = false;
|
||||
expect (!object.empty());
|
||||
}
|
||||
|
||||
void test_bad_json ()
|
||||
{
|
||||
char const* s (
|
||||
@@ -197,6 +220,7 @@ public:
|
||||
|
||||
void run ()
|
||||
{
|
||||
test_empty ();
|
||||
test_bad_json ();
|
||||
test_edge_cases ();
|
||||
test_copy ();
|
||||
|
||||
Reference in New Issue
Block a user