Remove support of unquoted keys

This commit is contained in:
Benoit Blanchon
2014-10-22 11:54:33 +02:00
parent 316d036785
commit d70ff26164
3 changed files with 35 additions and 16 deletions

View File

@ -66,20 +66,16 @@ static inline bool isQuote(char c)
char* QuotedString::extractFrom(char* input, char** endPtr)
{
char firstChar = *input;
char stopChar;
char* startPtr;
if (isQuote(firstChar))
if (!isQuote(firstChar))
{
stopChar = firstChar; // closing quote is the same as opening quote
startPtr = input + 1; // skip the quote
}
else
{
stopChar = ':'; // assume we're parsing a key in an object
startPtr = input; // no quote to skip
// must start with a quote
return 0;
}
char stopChar = firstChar; // closing quote is the same as opening quote
char* startPtr = input + 1; // skip the quote
char* readPtr = startPtr;
char* writePtr = startPtr;
char c;

View File

@ -68,8 +68,7 @@ TEST_F(JsonParser_Object_Test, MissingQuotesAndColonAndValue)
sizeMustBe(0);
}
TEST_F(JsonParser_Object_Test, OneStringNoSpace)
TEST_F(JsonParser_Object_Test, OneString)
{
whenInputIs("{\"key\":\"value\"}");
parseMustSucceed();
@ -77,6 +76,14 @@ TEST_F(JsonParser_Object_Test, OneStringNoSpace)
keyMustHaveValue("key", "value");
}
TEST_F(JsonParser_Object_Test, OneStringSingleQuotes)
{
whenInputIs("{'key':'value'}");
parseMustSucceed();
sizeMustBe(1);
keyMustHaveValue("key", "value");
}
TEST_F(JsonParser_Object_Test, OneStringSpaceBeforeKey)
{
whenInputIs("{ \"key\":\"value\"}");
@ -103,8 +110,17 @@ TEST_F(JsonParser_Object_Test, OneStringSpaceBeforeValue)
TEST_F(JsonParser_Object_Test, OneStringSpaceAfterValue)
{
whenInputIs("{\"key\":\"value\" }");
parseMustSucceed();
sizeMustBe(1);
keyMustHaveValue("key", "value");
whenInputIs("{\"key\":\"value\" }");
parseMustSucceed();
sizeMustBe(1);
keyMustHaveValue("key", "value");
}
TEST_F(JsonParser_Object_Test, TwoStrings)
{
whenInputIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
parseMustSucceed();
sizeMustBe(2);
keyMustHaveValue("key1", "value1");
keyMustHaveValue("key2", "value2");
}

View File

@ -37,6 +37,13 @@ TEST_F(QuotedString_ExtractFrom_Tests, EmptyDoubleQuotedString)
trailingMustBe("");
}
TEST_F(QuotedString_ExtractFrom_Tests, NoQuotes)
{
whenInputIs("hello world");
resultMustBe(0);
}
TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString)
{
whenInputIs("''");