Skip to content

safe-bash: malformed parameter expansion in legacy backticks fails at outer parse time #703

Description

@kamilio

Malformed parameter expansion inside a closed legacy-backtick substitution is currently rejected while parsing the outer script, although Bash accepts the script and reports the failure when the child substitution evaluates that word.

Reproduction:

printf 'BEFORE\n'; value=`printf '%s' "${value!}"`; code=$?; printf 'STATUS:%s VALUE:<%s>\n' "$code" "$value"; printf 'AFTER\n'

Current behavior: parseShell throws ShellSyntaxError: Unterminated or unsupported parameter expansion; Shell.exec exits 2 and the outer script does not continue.

GNU Bash 5.2.37 accepts the syntax. The malformed expansion fails inside the substitution with status 1, and the outer script continues:

BEFORE
STATUS:1 VALUE:<>
AFTER

The trace-shell compatibility RED reproduced the eager parser failure and outer exit-code mismatch on both MemoryFS and mock S3. The authenticated native fixture is 128 bytes with SHA-256 c01b8b24949870d3f5232ab547b0889f5386a1eea276e98c2e9d6fc52cecc084.

The fix should preserve the malformed expansion as a narrowly scoped runtime failure only within a closed ordinary backtick. Prior child output and effects should remain, later child work should stop, lazy branches/functions/default alternates should remain lazy, and the child status should flow through normal substitution capture. Keep top-level input, $(), process substitution, heredocs, unclosed backticks, array/special/numeric forms, depth limits, and cancellation behavior unchanged. Add paired MemoryFS/mock-S3 regression coverage.

A pending local candidate passes the focused compatibility checks but is not on origin/main or released.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions