Skip to content

Commit

Permalink
Fix FirebaseJson tokens extraction issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed May 12, 2021
1 parent 7274102 commit 490aca6
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.1.6
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.1.7


This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only).
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Firebase Arduino Client Library for ESP8266 and ESP32",
"version": "2.1.6",
"version": "2.1.7",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "This client library provides the functions to work with Firebase Realtime database, Firestore, Storage and Cloud messaging.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=Firebase Arduino Client Library for ESP8266 and ESP32

version=2.1.6
version=2.1.7

author=Mobizt

Expand Down
4 changes: 2 additions & 2 deletions src/Firebase_ESP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.1.6
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.1.7
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 11, 2021
* Created May 12, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down
4 changes: 2 additions & 2 deletions src/Firebase_ESP_Client.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.1.6
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h version 2.1.7
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 11, 2021
* Created May 12, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.1.6
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.1.7


The default filessystem used in the library is flash and SD.
Expand Down
56 changes: 36 additions & 20 deletions src/json/FirebaseJson.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* FirebaseJson, version 2.3.14
* FirebaseJson, version 2.3.15
*
* The Easiest Arduino library to parse, create and edit JSON object using a relative path.
*
* April 30, 2021
* May 12, 2021
*
* Features
* - None recursive operations
Expand Down Expand Up @@ -606,7 +606,7 @@ void FirebaseJson::_fbjs_parse(bool collectTk)
if (_parser_info.tokenCount < 0)
{
/** Not enough tokens were provided */
if (cnt == JSMN_ERROR_NOMEM)
if (_parser_info.tokenCount == JSMN_ERROR_NOMEM)
helper->setLastError(-2, __FILE__, __LINE__, fb_json_str_31);
}

Expand Down Expand Up @@ -2568,7 +2568,7 @@ bool FirebaseJson::remove(const String &path)
char *temp = helper->strP(fb_json_str_32);
size_t p1 = _rawbuf.find(temp);
helper->delS(temp);

if (p1 == std::string::npos)
{
temp = helper->strP(fb_json_str_33);
Expand Down Expand Up @@ -2756,8 +2756,7 @@ void FirebaseJson::_setElementType()
/**
* Allocates a fresh unused token from the token pool.
*/
FirebaseJson::fbjs_tok_t *FirebaseJson::fbjs_alloc_token(fbjs_parser *parser,
FirebaseJson::fbjs_tok_t *tokens, size_t num_tokens)
FirebaseJson::fbjs_tok_t *FirebaseJson::fbjs_alloc_token(fbjs_parser *parser, FirebaseJson::fbjs_tok_t *tokens, size_t num_tokens)
{
FirebaseJson::fbjs_tok_t *tok;
if (parser->toknext >= num_tokens)
Expand All @@ -2776,8 +2775,7 @@ FirebaseJson::fbjs_tok_t *FirebaseJson::fbjs_alloc_token(fbjs_parser *parser,
/**
* Fills token type and boundaries.
*/
void FirebaseJson::fbjs_fill_token(fbjs_tok_t *token, fbjs_type_t type,
int start, int end)
void FirebaseJson::fbjs_fill_token(fbjs_tok_t *token, fbjs_type_t type, int start, int end)
{
token->type = type;
token->start = start;
Expand All @@ -2788,8 +2786,7 @@ void FirebaseJson::fbjs_fill_token(fbjs_tok_t *token, fbjs_type_t type,
/**
* Fills next available token with JSON primitive.
*/
int FirebaseJson::fbjs_parse_primitive(fbjs_parser *parser, const char *js,
size_t len, fbjs_tok_t *tokens, size_t num_tokens)
int FirebaseJson::fbjs_parse_primitive(fbjs_parser *parser, const char *js, size_t len, fbjs_tok_t *tokens, size_t num_tokens)
{
fbjs_tok_t *token;
int start;
Expand Down Expand Up @@ -2848,8 +2845,7 @@ int FirebaseJson::fbjs_parse_primitive(fbjs_parser *parser, const char *js,
/**
* Fills next token with JSON string.
*/
int FirebaseJson::fbjs_parse_string(fbjs_parser *parser, const char *js,
size_t len, fbjs_tok_t *tokens, size_t num_tokens)
int FirebaseJson::fbjs_parse_string(fbjs_parser *parser, const char *js, size_t len, fbjs_tok_t *tokens, size_t num_tokens)
{
fbjs_tok_t *token;

Expand Down Expand Up @@ -2930,14 +2926,13 @@ int FirebaseJson::fbjs_parse_string(fbjs_parser *parser, const char *js,
/**
* Parse JSON string and fill tokens.
*/
int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
fbjs_tok_t *tokens, unsigned int num_tokens)
int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len, fbjs_tok_t *tokens, unsigned int num_tokens)
{
int r;
int i;
fbjs_tok_t *token;
int count = parser->toknext;

for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++)
{
char c;
Expand All @@ -2955,10 +2950,20 @@ int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
}
token = fbjs_alloc_token(parser, tokens, num_tokens);
if (token == NULL)
{
return JSMN_ERROR_NOMEM;
}
if (parser->toksuper != -1)
{
tokens[parser->toksuper].size++;
fbjs_tok_t *t = &tokens[parser->toksuper];
#ifdef JSMN_STRICT
/* In strict mode an object or array can't become a key */
if (t->type == JSMN_OBJECT)
{
return JSMN_ERROR_INVAL;
}
#endif
t->size++;
#ifdef JSMN_PARENT_LINKS
token->parent = parser->toksuper;
#endif
Expand All @@ -2973,7 +2978,9 @@ int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
case '}':
case ']':
if (tokens == NULL)
{
break;
}
type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
#ifdef JSMN_PARENT_LINKS
if (parser->toknext < 1)
Expand Down Expand Up @@ -3020,7 +3027,9 @@ int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
}
/* Error if unmatched closing bracket */
if (i == -1)
{
return JSMN_ERROR_INVAL;
}
for (; i >= 0; i--)
{
token = &tokens[i];
Expand All @@ -3035,10 +3044,14 @@ int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
case '\"':
r = fbjs_parse_string(parser, js, len, tokens, num_tokens);
if (r < 0)
{
return r;
}
count++;
if (parser->toksuper != -1 && tokens != NULL)
{
tokens[parser->toksuper].size++;
}
break;
case '\t':
case '\r':
Expand Down Expand Up @@ -3086,11 +3099,10 @@ int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
case 't':
case 'f':
case 'n':

/* And they must not be keys of the object */
if (tokens != NULL && parser->toksuper != -1)
{
fbjs_tok_t *t = &tokens[parser->toksuper];
const fbjs_tok_t *t = &tokens[parser->toksuper];
if (t->type == JSMN_OBJECT ||
(t->type == JSMN_STRING && t->size != 0))
{
Expand All @@ -3101,19 +3113,23 @@ int FirebaseJson::fbjs_parse(fbjs_parser *parser, const char *js, size_t len,
/* In non-strict mode every unquoted value is a primitive */
default:
#endif

r = fbjs_parse_primitive(parser, js, len, tokens, num_tokens);
if (r < 0)
{
return r;
}
count++;
if (parser->toksuper != -1 && tokens != NULL)
{
tokens[parser->toksuper].size++;
}
break;

#ifdef JSMN_STRICT
/* Unexpected char in strict mode */
default:
return JSMN_ERROR_INVAL;
if (tokens != NULL)
return JSMN_ERROR_INVAL;
#endif
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/json/FirebaseJson.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* FirebaseJson, version 2.3.14
* FirebaseJson, version 2.3.15
*
* The Easiest Arduino library to parse, create and edit JSON object using a relative path.
*
* April 30, 2021
* May 12, 2021
*
* Features
* - None recursive operations
Expand Down

0 comments on commit 490aca6

Please sign in to comment.