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* QuotedString::extractFrom(char* input, char** endPtr)
{ {
char firstChar = *input; char firstChar = *input;
char stopChar;
char* startPtr;
if (isQuote(firstChar)) if (!isQuote(firstChar))
{ {
stopChar = firstChar; // closing quote is the same as opening quote // must start with a quote
startPtr = input + 1; // skip the quote return 0;
}
else
{
stopChar = ':'; // assume we're parsing a key in an object
startPtr = input; // no quote to skip
} }
char stopChar = firstChar; // closing quote is the same as opening quote
char* startPtr = input + 1; // skip the quote
char* readPtr = startPtr; char* readPtr = startPtr;
char* writePtr = startPtr; char* writePtr = startPtr;
char c; char c;

View File

@ -68,8 +68,7 @@ TEST_F(JsonParser_Object_Test, MissingQuotesAndColonAndValue)
sizeMustBe(0); sizeMustBe(0);
} }
TEST_F(JsonParser_Object_Test, OneString)
TEST_F(JsonParser_Object_Test, OneStringNoSpace)
{ {
whenInputIs("{\"key\":\"value\"}"); whenInputIs("{\"key\":\"value\"}");
parseMustSucceed(); parseMustSucceed();
@ -77,6 +76,14 @@ TEST_F(JsonParser_Object_Test, OneStringNoSpace)
keyMustHaveValue("key", "value"); keyMustHaveValue("key", "value");
} }
TEST_F(JsonParser_Object_Test, OneStringSingleQuotes)
{
whenInputIs("{'key':'value'}");
parseMustSucceed();
sizeMustBe(1);
keyMustHaveValue("key", "value");
}
TEST_F(JsonParser_Object_Test, OneStringSpaceBeforeKey) TEST_F(JsonParser_Object_Test, OneStringSpaceBeforeKey)
{ {
whenInputIs("{ \"key\":\"value\"}"); whenInputIs("{ \"key\":\"value\"}");
@ -103,8 +110,17 @@ TEST_F(JsonParser_Object_Test, OneStringSpaceBeforeValue)
TEST_F(JsonParser_Object_Test, OneStringSpaceAfterValue) TEST_F(JsonParser_Object_Test, OneStringSpaceAfterValue)
{ {
whenInputIs("{\"key\":\"value\" }"); whenInputIs("{\"key\":\"value\" }");
parseMustSucceed(); parseMustSucceed();
sizeMustBe(1); sizeMustBe(1);
keyMustHaveValue("key", "value"); 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(""); trailingMustBe("");
} }
TEST_F(QuotedString_ExtractFrom_Tests, NoQuotes)
{
whenInputIs("hello world");
resultMustBe(0);
}
TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString) TEST_F(QuotedString_ExtractFrom_Tests, EmptySingleQuotedString)
{ {
whenInputIs("''"); whenInputIs("''");