mobizt / Firebase-ESP32

[DEPRECATED]🔥 Firebase RTDB Arduino Library for ESP32. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
414 stars 119 forks source link

Help #286

Closed Helmar0 closed 10 months ago

Helmar0 commented 10 months ago

Subject: Bug Report - Firebase-ESP32 JSON Array Iteration Issue

Dear Firebase-ESP32 Developers,

I hope this message finds you well. I am writing to report a technical issue I encountered while using the Firebase-ESP32 library (v4.3.19) for JSON array iteration.

Issue Description: I have been using the Firebase-ESP32 library to work with JSON objects successfully. However, I noticed an issue when iterating through JSON arrays. Specifically, the problem occurs after the first iteration of a JSON array, where the pointer ofs that points to the value becomes invalid, causing incorrect behavior during subsequent iterations.

Steps to Reproduce:

  1. Initialize the Firebase-ESP32 library (v4.3.19).
  2. Retrieve a JSON object that contains arrays.
  3. Use the iteratorGet() method to iterate through the JSON arrays.
  4. Observe that the ofs pointer behaves correctly during the first iteration but becomes invalid in subsequent iterations.

Expected Behavior: I expect the ofs pointer to remain valid and correctly point to the value of JSON array elements during all iterations.

Additional Information:

Impact: This issue affects my project, as I rely on the correct iteration of JSON arrays within my application.

Screenshots: [If applicable, attach any relevant screenshots or code snippets that demonstrate the issue.]

Possible Solution: [If you have any insights or suggestions for a potential solution, please provide them here.]

I believe that addressing this issue would enhance the functionality and reliability of the Firebase-ESP32 library. I am willing to assist in any way I can to help diagnose and resolve this problem. Please let me know if you need further information or assistance.

Thank you for your attention to this matter, and I look forward to your response.

Sincerely, Helmar Alvares helmaralvares@yahoo.com.br

mobizt commented 10 months ago

Please write the minimal but complete code to reproduce the issue.

Helmar0 commented 10 months ago

Problem Description: I am encountering an issue with the Firebase-ESP32 library (version 4.3.19) when parsing nested JSON arrays. The library seems to misinterpret the data type of values when nested arrays are encountered, resulting in incorrect parsing.

Context: Here's an example JSON structure and code snippet that reproduces the problem:

JSON: { "keyA": { "node0": "k5g6WzEGh7gdpvnjlySDN63wKKf1", "node1": "-Luic_vkdrxV9PS0AI_D", "array0": { "id_0": [2005, 2006], "w_0": [100, 234] }, "node2": 1693871915, "node3": 1693859573, "node4": 1036 }, "keyB": { "node0": "k5g6WzEGh7gdpvnjlySDN63wKKf1", "node1": "-Luic_vkdrxV9PS0AI_D", "array1": { "id_1": [1033, 1047], "q_1": [3, 2] }, "array0": { "id_0": [2008, 2005], "w_0": [101, 109] }, "node2": 1693873400, "node3": 1693880678, "node4": 1040 } }

Code to Reproduce:

void iteratorJson() { String jsonStr; jsonORDER.toString(jsonStr, false); size_t len = jsonORDER.iteratorBegin(); String key = "", value = ""; int type = 0; for (size_t i = 0; i < len; i++) { jsonORDER.iteratorGet(i, type, key, value); Serial.println("json ---> i: " + String(i) + " key: " + key + " value: " + value); } jsonORDER.iteratorEnd(); }

Expected Result: I expect that when parsing nested JSON arrays (e.g., "id_0": [2005, 2006]), all values within the array should be correctly interpreted as numbers.

Current Result: The current behavior is that, when parsing nested JSON arrays, only the first value is correctly interpreted as a number, while subsequent values are not. For example, "id_0" should be parsed as [2005, 2006], but it is being interpreted as 2005 and 2006 individually.

Library Version: I am using Firebase-ESP32 library version 4.3.19.

Steps to Reproduce: Initialize Firebase-ESP32. Parse the provided JSON structure using the iteratorJson function. Observe that nested JSON arrays are not correctly parsed, leading to incorrect interpretation of values. You can use this description as a basis for reporting the issue to the library's developers. Feel free to adapt and expand upon it as needed to ensure that the problem is well-documented and clear for them to understand.

Message to Developers: I would like to express my gratitude to the developers for their prompt attention to this issue. Your dedication to improving the library is greatly appreciated.

mobizt commented 10 months ago

Ok I found the issue but not because parsing but incorrect value copying from source using text find.

The iteration is for elements extraction without parsing.

The problem occurred when the keys contain in the values that cause text search returns invalid index.

I will fix it based on incorrect value extraction.

mobizt commented 10 months ago

The new version v4.4.0 with a lot of improvements and bugs fixed is now available.

Please update.

Helmar0 commented 10 months ago

Dear Mobizt,

I hope this message finds you well. I wanted to take a moment to express my heartfelt gratitude for your dedication and efficiency in crafting the latest version, Firebase-ESP32 library version 4.4.0.

Your prompt response to the issues I reported and the swift resolution of the bugs have been truly remarkable. It's clear that you have poured a great deal of time and effort into enhancing the library, and I am immensely grateful for your commitment to creating a reliable and effective tool.

I'm delighted to inform you that after extensive testing, the 4.4.0 version of the library is performing exceptionally well in my application. It has not only addressed the previously reported issues but has also introduced valuable improvements. Your hard work has made a significant impact on the functionality and stability of my project.

I understand the challenges that come with developing and maintaining open-source libraries, and I want to acknowledge your outstanding work. Your library has been an essential component of my project, and your responsiveness to user feedback is truly commendable.

Once again, thank you for your dedication to the Firebase community. Your efforts have empowered developers like me to create robust and reliable applications. I look forward to continued collaboration and the future advancements of the Firebase-ESP32 library.

Warm regards and sincere thanks,

Helma Alvares

mobizt commented 10 months ago

Thanks Helma,

Please update the library to the latest v4.4.2 which network reconnection, SSL client and internal reference time issues are now fixed.