mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 20:12:16 +02:00
Parse invalid array
This commit is contained in:
@ -147,3 +147,20 @@ void JsonNode::setAsProxyOfSelf()
|
|||||||
|
|
||||||
setAsProxyOf(newNode);
|
setAsProxyOf(newNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonNode::duplicate(JsonNode* other)
|
||||||
|
{
|
||||||
|
if (!other)
|
||||||
|
{
|
||||||
|
type = JSON_UNDEFINED;
|
||||||
|
}
|
||||||
|
else if (other->type == JSON_ARRAY || other->type==JSON_OBJECT)
|
||||||
|
{
|
||||||
|
other->setAsProxyOfSelf();
|
||||||
|
setAsProxyOf(other->content.asProxy.target);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*this = *other;
|
||||||
|
}
|
||||||
|
}
|
@ -152,26 +152,16 @@ public:
|
|||||||
return type == JSON_PROXY ? content.asProxy.target : this;
|
return type == JSON_PROXY ? content.asProxy.target : this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isArray()
|
||||||
|
{
|
||||||
|
return type == JSON_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
void addChild(JsonNode* childToAdd);
|
void addChild(JsonNode* childToAdd);
|
||||||
|
|
||||||
void removeChild(JsonNode* childToRemove);
|
void removeChild(JsonNode* childToRemove);
|
||||||
|
|
||||||
void duplicate(JsonNode* other)
|
void duplicate(JsonNode* other);
|
||||||
{
|
|
||||||
if (!other)
|
|
||||||
{
|
|
||||||
type = JSON_UNDEFINED;
|
|
||||||
}
|
|
||||||
else if (other->type == JSON_ARRAY || other->type==JSON_OBJECT)
|
|
||||||
{
|
|
||||||
other->setAsProxyOfSelf();
|
|
||||||
setAsProxyOf(other->content.asProxy.target);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*this = *other;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonNode* next;
|
JsonNode* next;
|
||||||
|
@ -25,5 +25,10 @@ public:
|
|||||||
|
|
||||||
JsonArray createNestedArray();
|
JsonArray createNestedArray();
|
||||||
JsonObject createNestedObject();
|
JsonObject createNestedObject();
|
||||||
|
|
||||||
|
bool success()
|
||||||
|
{
|
||||||
|
return _node && _node->isArray();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#include "JsonBuffer.h"
|
#include "JsonBuffer.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <string.h> // for memset
|
|
||||||
|
|
||||||
#include "JsonObject.h"
|
|
||||||
#include "JsonValue.h"
|
#include "JsonValue.h"
|
||||||
#include "Internals/JsonNode.h"
|
#include "Internals/JsonNode.h"
|
||||||
|
|
||||||
@ -20,7 +18,19 @@ JsonNode* JsonBuffer::createNode()
|
|||||||
return new (node) JsonNode();
|
return new (node) JsonNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray JsonBuffer::parseArray(char const *string)
|
JsonArray JsonBuffer::parseArray(const char* json)
|
||||||
{
|
{
|
||||||
return JsonArray();
|
JsonNode* root;
|
||||||
|
|
||||||
|
if (json[0] == '[')
|
||||||
|
{
|
||||||
|
root = createNode();
|
||||||
|
root->setAsArray(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
root = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonArray(root);
|
||||||
}
|
}
|
@ -11,5 +11,14 @@ TEST_F(JsonArray_Parser_Tests, EmptyArray)
|
|||||||
{
|
{
|
||||||
JsonArray array = json.parseArray("[]");
|
JsonArray array = json.parseArray("[]");
|
||||||
|
|
||||||
|
EXPECT_TRUE(array.success());
|
||||||
|
EXPECT_EQ(0, array.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JsonArray_Parser_Tests, Garbage)
|
||||||
|
{
|
||||||
|
JsonArray array = json.parseArray("%*$£¤");
|
||||||
|
|
||||||
|
EXPECT_FALSE(array.success());
|
||||||
EXPECT_EQ(0, array.size());
|
EXPECT_EQ(0, array.size());
|
||||||
}
|
}
|
Reference in New Issue
Block a user