Skip to content

Commit

Permalink
Fix: skip BOM in JSON files (pin_mapping and config)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Oct 29, 2024
1 parent dc5eb96 commit 4428fbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/PinMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4428fbc

Please sign in to comment.