From 993f3213a122dcb0b698d6cc9c5a82918d5c5f1e Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Tue, 29 Oct 2024 10:00:04 +0100 Subject: [PATCH] Fix: skip BOM in JSON files (pin_mapping and config) --- src/Configuration.cpp | 7 +++++++ src/PinMapping.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/Configuration.cpp b/src/Configuration.cpp index b260ccee2..ec3027bc1 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -397,6 +397,13 @@ bool ConfigurationClass::read() { File f = LittleFS.open(CONFIG_FILENAME, "r", false); + // skip Byte Order Mask (BOM). valid JSON docs always start with '{' or '['. + while (f.available() > 0) { + int c = f.peek(); + if (c == '{' || c == '[') { break; } + f.read(); + } + JsonDocument doc; // Deserialize the JSON document diff --git a/src/PinMapping.cpp b/src/PinMapping.cpp index 9f6272173..c2c411595 100644 --- a/src/PinMapping.cpp +++ b/src/PinMapping.cpp @@ -321,6 +321,13 @@ bool PinMappingClass::init(const String& deviceMapping) return false; } + // skip Byte Order Mask (BOM). valid JSON docs always start with '{' or '['. + while (f.available() > 0) { + int c = f.peek(); + if (c == '{' || c == '[') { break; } + f.read(); + } + JsonDocument doc; // Deserialize the JSON document DeserializationError error = deserializeJson(doc, f);