Skip to content

[bug] Empty-case strictness divergence: 'case x in' + newline + 'esac)' silently accepted (GNU: syntax error near unexpected token ')') #381

Closed

Description

@caomengxuan666

Found by the wt25/semix lane while fixing #372 (reverse divergence: GNU strict, rubash lax).

Shape

case x in
esac) echo hi;;
esac
  • WSL GNU Bash 5.3.0: syntax error near unexpected token ')' — an esac immediately following in is the ESAC token (empty case body), so the ) is stray.
  • rubash (current master): silently accepts and runs.

Root pointer (lane's analysis)

parse_case_command's empty-case check does not skip the newline(s) after in before deciding the body is empty, so the following esac) gets consumed as if a pattern were allowed. GNU owner: the case-clause reader in parse.y (case_clause/case_item sequence; in then NEWLINE then ESAC closes the case at the grammar level — a ) after that is a stray token error).

Fix-lane notes

Small, but it is a strictness divergence (we accept scripts GNU rejects) — worth pinning with a both-directions regression: case x in\nesac) (error) vs case x in\n(esac) (pattern esac, valid) vs case x in esac) on one line.

Activity

  1. added 2 commits that reference this issue on Oct 1, 2026
  2. caomengxuan666 commented on Oct 1, 2026

    @caomengxuan666
    MemberAuthor

    Landed as 600cf42 (wt29/rubugs lane a3851274). parse_case_command's empty-case check now skips the newline_list after in (parse.y:1037) before testing for esac; a stray )/( there reports RUBASH_PARSE_ERROR_NEAR exactly like GNU's syntax error near unexpected token )`` (| stays a legal pipe, reported at the trailing `)`). Both-directions matrix 13/14 byte-identical (residual: comsub-wrapped form's source-line echo attribution, pre-existing). issue381 suite 7/7. CI green.

  3. added
    bug
    area:parser
    on Oct 17, 2026
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

    area:parserbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions