@@ -373,7 +373,11 @@ bool check_rules_line_user_errors(String& line)
373
373
\*********************************************************************************************/
374
374
bool get_next_inner_bracket (const String& line, int & startIndex, int & closingIndex, char closingBracket)
375
375
{
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;
377
381
378
382
switch (closingBracket) {
379
383
case ' ]' : openingBracket = ' [' ; break ;
@@ -383,11 +387,15 @@ bool get_next_inner_bracket(const String& line, int& startIndex, int& closingInd
383
387
// unknown bracket type
384
388
return false ;
385
389
}
386
- closingIndex = line.indexOf (closingBracket);
390
+ // Closing bracket should not be found on the first position.
391
+ closingIndex = line.indexOf (closingBracket, startIndex + 1 );
387
392
388
- if (closingIndex == -1 ) { return false ; }
393
+ if (closingIndex == -1 ) {
394
+ // not found
395
+ return false ;
396
+ }
389
397
390
- for (int i = closingIndex; i >= 0 ; --i) {
398
+ for (int i = ( closingIndex - 1 ) ; i > startIndex ; --i) {
391
399
if (line[i] == openingBracket) {
392
400
startIndex = i;
393
401
return true ;
@@ -542,7 +550,8 @@ bool parse_math_functions(const String& cmd_s_lower, const String& arg1, const S
542
550
}
543
551
544
552
void parse_string_commands (String& line) {
545
- int startIndex, closingIndex;
553
+ int startIndex = 0 ;
554
+ int closingIndex;
546
555
547
556
while (get_next_inner_bracket (line, startIndex, closingIndex, ' }' )) {
548
557
// Command without opening and closing brackets.
0 commit comments