From 4428fbcf1ee70da4d82e74e25c039eb209770aa6 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 db47d9c8a..aefde2c7a 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -160,6 +160,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 bd5ea9952..52fff79f7 100644 --- a/src/PinMapping.cpp +++ b/src/PinMapping.cpp @@ -199,6 +199,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);