Fix: skip BOM in JSON files (pin_mapping and config)

This commit is contained in:
Bernhard Kirchen 2024-10-29 10:00:04 +01:00
parent 3c1d3f7207
commit 993f3213a1
2 changed files with 14 additions and 0 deletions

View File

@ -397,6 +397,13 @@ bool ConfigurationClass::read()
{ {
File f = LittleFS.open(CONFIG_FILENAME, "r", false); 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; JsonDocument doc;
// Deserialize the JSON document // Deserialize the JSON document

View File

@ -321,6 +321,13 @@ bool PinMappingClass::init(const String& deviceMapping)
return false; 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; JsonDocument doc;
// Deserialize the JSON document // Deserialize the JSON document
DeserializationError error = deserializeJson(doc, f); DeserializationError error = deserializeJson(doc, f);