Skip to content

Commit 2556826

Browse files
authored
Merge pull request letscontrolit#3874 from TD-er/bugfix/parse_empty_command
[dashboard] Fix crash on parsing empty command {} (letscontrolit#3873)
2 parents 549f76e + 079744f commit 2556826

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/src/ESPEasyCore/ESPEasyRules.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ bool check_rules_line_user_errors(String& line)
373373
\*********************************************************************************************/
374374
bool get_next_inner_bracket(const String& line, int& startIndex, int& closingIndex, char closingBracket)
375375
{
376-
char openingBracket = closingIndex;
376+
if (line.length() <= 1) {
377+
// Not possible to have opening and closing bracket on a line this short.
378+
return false;
379+
}
380+
char openingBracket = closingBracket;
377381

378382
switch (closingBracket) {
379383
case ']': openingBracket = '['; break;
@@ -383,11 +387,15 @@ bool get_next_inner_bracket(const String& line, int& startIndex, int& closingInd
383387
// unknown bracket type
384388
return false;
385389
}
386-
closingIndex = line.indexOf(closingBracket);
390+
// Closing bracket should not be found on the first position.
391+
closingIndex = line.indexOf(closingBracket, startIndex + 1);
387392

388-
if (closingIndex == -1) { return false; }
393+
if (closingIndex == -1) {
394+
// not found
395+
return false;
396+
}
389397

390-
for (int i = closingIndex; i >= 0; --i) {
398+
for (int i = (closingIndex - 1); i > startIndex; --i) {
391399
if (line[i] == openingBracket) {
392400
startIndex = i;
393401
return true;
@@ -542,7 +550,8 @@ bool parse_math_functions(const String& cmd_s_lower, const String& arg1, const S
542550
}
543551

544552
void parse_string_commands(String& line) {
545-
int startIndex, closingIndex;
553+
int startIndex = 0;
554+
int closingIndex;
546555

547556
while (get_next_inner_bracket(line, startIndex, closingIndex, '}')) {
548557
// Command without opening and closing brackets.

0 commit comments

Comments
 (0)