Skip to content

Commit

Permalink
Fix FirebaseJson set/remove bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Nov 14, 2019
1 parent 035eecf commit c786dfe
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Realtime Database Arduino Library for ESP8266


Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.8
Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.9


This library supports ESP8266 MCU from Espressif. The following are platforms which library are also available.
Expand Down Expand Up @@ -48,7 +48,7 @@ This library supports ESP8266 MCU from Espressif. The following are platforms wh

## Changes from earlier version

For library v 2.6.8 (comes with FirebaseJson v 2.2.5) or later, FirebaseJson object will be used to handle JSON data instead of JSON string which, the following functions are affected:
For library v 2.6.9 (comes with FirebaseJson v 2.2.6) or later, FirebaseJson object will be used to handle JSON data instead of JSON string which, the following functions are affected:

getJson, setJson, pushJson, updateNode and updateNodeSilent.

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 ESP8266 Client

version=2.6.8
version=2.6.9

author=Mobizt

Expand Down
6 changes: 3 additions & 3 deletions src/FirebaseESP8266.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.8
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.9
*
* November 13, 2019
* November 14, 2019
*
* Feature Added:
*
* Feature Fixed:
* - Fix internal clock setting for BearSSL if root CA was set (ESP8266 Core SDK 2.5.x or later).
* - Fix FirebaseJson set/remove bugs.
*
*
* This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update
Expand Down
6 changes: 3 additions & 3 deletions src/FirebaseESP8266.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.8
* Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.9
*
* November 13, 2019
* November 14, 2019
*
* Feature Added:
*
* Feature Fixed:
* - Fix internal clock setting for BearSSL if root CA was set (ESP8266 Core SDK 2.5.x or later).
* - Fix FirebaseJson set/remove bugs.
*
*
* This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update
Expand Down
59 changes: 32 additions & 27 deletions src/FirebaseJson.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* FirebaseJson, version 2.2.5
* FirebaseJson, version 2.2.6
*
* The Easiest ESP8266/ESP32 Arduino library for parse, create and edit JSON object using relative path.
*
* November 12, 2019
* November 14, 2019
*
* Features
* - None recursive operations
Expand Down Expand Up @@ -647,34 +647,36 @@ bool FirebaseJson::_updateTkIndex(uint16_t index, int &depth, char *searchKey, i
{
if (!advanceCount)
_parseCompleted++;
if (_el[i].type == JSMN_OBJECT)

if (!_arrReplaced)
{
if (printMode == PRINT_MODE_PRETTY)
if (_el[i].type == JSMN_OBJECT && !_arrReplaced)
{
for (int j = 0; j < depth + 2; j++)
_jsonData._dbuf += _tab;
if (printMode == PRINT_MODE_PRETTY)
{
for (int j = 0; j < depth + 2; j++)
_jsonData._dbuf += _tab;
}
_jsonData._dbuf += _qt;
_jsonData._dbuf += searchKey;
_jsonData._dbuf += _qt;
if (printMode == PRINT_MODE_PRETTY)
_jsonData._dbuf += _pr;
else
_jsonData._dbuf += _pr2;
if (_parseCompleted == (int)_pathTk.size())
_jsonData._dbuf += replace;
else
_insertChilds(replace, printMode);
_arrReplaced = true;
if (printMode == PRINT_MODE_PRETTY)
{
_jsonData._dbuf += _nl;
for (int j = 0; j < depth + 1; j++)
_jsonData._dbuf += _tab;
}
}
_jsonData._dbuf += _qt;
_jsonData._dbuf += searchKey;
_jsonData._dbuf += _qt;
if (printMode == PRINT_MODE_PRETTY)
_jsonData._dbuf += _pr;
else
_jsonData._dbuf += _pr2;
if (_parseCompleted == (int)_pathTk.size())
_jsonData._dbuf += replace;
else
_insertChilds(replace, printMode);
if (printMode == PRINT_MODE_PRETTY)
{
_jsonData._dbuf += _nl;
for (int j = 0; j < depth + 1; j++)
_jsonData._dbuf += _tab;
}
}
else
{
if (!_arrReplaced)
{
for (int k = _el[i].oindex - 1; k < searchIndex; k++)
{
Expand Down Expand Up @@ -704,6 +706,7 @@ bool FirebaseJson::_updateTkIndex(uint16_t index, int &depth, char *searchKey, i
if (!advanceCount)
_parseCompleted = _pathTk.size();
}

if (_el[i].type == JSMN_OBJECT)
_jsonData._dbuf += _brk2;
else
Expand Down Expand Up @@ -1537,12 +1540,13 @@ void FirebaseJson::_compileToken(uint16_t &i, char *buf, int &depth, char *searc
_jsonData._dbuf += _tab;
}

if (_refToken == i + 1)
if (_refToken == i + 1 && !_arrInserted)
{
if (!insertFlag)
_jsonData._dbuf += replace;
else
_insertChilds(replace, printMode);
_arrInserted = true;
}
else
_jsonData._dbuf += tmp;
Expand Down Expand Up @@ -2160,6 +2164,7 @@ void FirebaseJson::_set(const char *path, const char *data)
_TkRefOk = false;
_parseCompleted = 0;
_arrReplaced = false;
_arrInserted = false;
_refTkIndex = -1;
_remTkIndex = -1;
_remFirstTk = false;
Expand Down
5 changes: 3 additions & 2 deletions src/FirebaseJson.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* FirebaseJson, version 2.2.5
* FirebaseJson, version 2.2.6
*
* The Easiest ESP8266/ESP32 Arduino library for parse, create and edit JSON object using relative path.
*
* November 12, 2019
* November 14, 2019
*
* Features
* - None recursive operations
Expand Down Expand Up @@ -557,6 +557,7 @@ class FirebaseJson
bool _collectTk = false;
bool _paresRes = false;
bool _arrReplaced = false;
bool _arrInserted = false;

char *_qt = nullptr;
char *_tab = nullptr;
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 Realtime Database Arduino Library for ESP8266


Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.8
Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.9


## Global functions
Expand Down

0 comments on commit c786dfe

Please sign in to comment.