Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in decode unicode #1173

Closed
fvanroie opened this issue Jan 26, 2020 · 2 comments
Closed

Regression in decode unicode #1173

fvanroie opened this issue Jan 26, 2020 · 2 comments
Labels
bug v6 ArduinoJson 6

Comments

@fvanroie
Copy link

fvanroie commented Jan 26, 2020

Problem Description

I am using the ARDUINOJSON_DECODE_UNICODE=1 compiler flag to enable the decode unicode feature of ArduinoJson.

After upgrading to version 6.14.0 of the library, unicode characters read from a json lines file are not decoded properly anymore. There seems to be a shift of 0x1000 in the decoded character codepoint.

Switching back to version 6.13.0 solves the problem.

Target Platform

ESP8266 & ESP32

Compiler model and version

CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/d1_mini.html
PLATFORM: Espressif 8266 2.3.2 > WeMos D1 R2 and mini
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: toolchain-xtensa 2.40802.191122 (4.8.2),
framework-arduinoespressif8266 2.20603.191216 (2.6.3),
tool-esptool 1.413.0 (4.13), tool-esptoolpy 1.20800.0 (2.8.0),
tool-mkspiffs 1.200.0 (2.0)

platformio.ini configuration file:

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
upload_port = COM4       ; Change to the correct port
monitor_port = COM4      ; Change to the correct port
monitor_speed = 115200
upload_speed = 921600
lib_deps =
    [email protected]   ; 6.14.0 breaks unicode decoding!
build_flags =
    -D SPIFFS_TEMPORAL_FD_CACHE     ; speed up opening recent files
    -D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols
    -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
board_build.f_flash = 40000000L
board_build.flash_mode = dout

Minimal, Complete and Verifiable Example

#include <Arduino.h>
#include "ArduinoJson.h"
#include "FS.h"

void setup()
{
  Serial.begin(115200); /* prepare for possible serial debug */
  Serial.flush();
  Serial.println();

  SPIFFS.begin();
  if (!SPIFFS.begin())
    Serial.println("FILE: %sSPI flash init failed. Unable to mount FS.");
  else
    Serial.println("FILE: [SUCCESS] SPI flash FS mounted");

  File file = SPIFFS.open("/pages.jsonl", "r");
  if (!file)
    Serial.println("FILE: File not opened");
  else
    Serial.println("FILE: [SUCCESS] file opened");

  DynamicJsonDocument config(256);
  while (deserializeJson(config, file) == DeserializationError::Ok)
  {
    serializeJson(config, Serial);
    Serial.println();

    String message = config["txt"].as<String>();

    byte bytes[message.length() + 1];
    message.getBytes(bytes, message.length() + 1);

    for (int i = 0; i < sizeof(bytes); i++)
    {
      Serial.print(bytes[i], HEX);
      Serial.print(" ");
    }
    Serial.println("\n");
  }
  file.close();
}

void loop()
{
  // put your main code here, to run repeatedly:
}

Contents of input file /pages.jsonl uploaded to SPIFFS:

{"txt":"\uF053 Prev"}
{"txt":"\uF015 Home"}
{"txt":"Next \uF054"}

Result

Test 1 Using version 6.13.0

lib_deps =
    [email protected]

Result:

{"txt":" Prev"}
EF 81 93 20 50 72 65 76 0

{"txt":" Home"}
EF 80 95 20 48 6F 6D 65 0

{"txt":"Next "}
4E 65 78 74 20 EF 81 94 0

Test 2 Using version 6.14.0

lib_deps =
    [email protected]

Result:

{"txt":"𐁓 Prev"}
F0 90 81 93 20 50 72 65 76 0

{"txt":"𐀕 Home"}
F0 90 80 95 20 48 6F 6D 65 0

{"txt":"Next 𐁔"}
4E 65 78 74 20 F0 90 81 94 0

Conclusion

The decoded unicode characters \uF053 \uF015 \uF054 are shifted by 0x1000:

Relevant Output Received Unicode Character
Test 1 EF 81 93
EF 80 95
EF 81 94
\uF053
\uF015
\uF054
Test 2 F0 90 81 93
F0 90 80 95
F0 90 81 94
‭\u10053‬
\u10015
\u‭10054‬
bblanchon added a commit that referenced this issue Jan 27, 2020
@bblanchon bblanchon added the bug label Jan 27, 2020
@bblanchon
Copy link
Owner

Hi @fvanroie,

Thank you very much for this accurate bug report.
I fixed the regression in ArduinoJson 6.14.1.
Sorry about that.

Best regards,
Benoit

@fvanroie
Copy link
Author

fvanroie commented Jan 28, 2020

Hello @bblanchon

No problem at all, you're welcome. In fact, thank you for the quick resolution and for providing an indispensable library.

I tested 6.14.1 and it is working correctly now!

Merci beaucoup,
Francis

@lock lock bot locked as resolved and limited conversation to collaborators Feb 28, 2020
stawiski pushed a commit to stawiski/ArduinoJson that referenced this issue Jul 28, 2020
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants