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 3c1d3f7 commit 993f321
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 @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/PinMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 993f321

Please sign in to comment.