Skip to content

Parser: array subscript reader stops at first ] ignoring nested ${...} #600

@chaliy

Description

@chaliy

Bug

The parser's array subscript reader in parser/mod.rs stops at the first ] character without tracking nesting. For expressions like:

${names[$RANDOM % ${#names[@]}]}

the subscript is read as $RANDOM % ${#names[ — stopping at the ] inside ${#names[@]} — instead of the full $RANDOM % ${#names[@]}.

Root cause

Around line 2390 in parse_word(), the subscript reader is:

while let Some(&c) = chars.peek() {
    if c == ']' {
        chars.next();
        break;
    }
    index.push(chars.next().unwrap());
}

No bracket or brace depth tracking.

Fix

Track [] bracket depth and ${} brace depth when reading subscript content, so nested expressions don't prematurely end the subscript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions