Skip to content

rollup.rb treats # parameter-expansion operators as comments #27

Description

@memotype

Severity: Medium
Expected real-world likelihood: Medium for future maintenance; none in the current source

Problem

rollup.rb removes text from any unprotected # through the end of the line. Valid Bash parameter expansions use the same character for length and prefix removal, so adding an ordinary construct such as ${#array[@]} or ${value#prefix} to the readable source can silently corrupt generated scripts.

The current bj.sh does not contain an affected core construct, and current generated files reproduce byte-for-byte. This is a guardrail issue for future compact parser work rather than a current runtime regression.

Reproduction

printf '%s\n' 'x=${#a[@]}' 'y=${value#prefix}' | ./rollup.rb

Actual compact code after the copyright header:

x=${y=${value

The source lines are valid Bash but are truncated at each #.

Suspected cause

The transformation list includes:

[/#.*\n/, '']

Quoted string literals are protected before transformations, but unquoted parameter expansions are not.

Possible fixes (suggestions only)

These are possible approaches, not prescribed implementations:

  • Protect the small set of Bash parameter-expansion forms containing # before comment stripping and restore them afterward.
  • Narrow comment recognition so # inside a parameter expansion is not treated as a comment.
  • Add focused generator fixtures for the supported compact Bash constructs.

The solution should remain small and auditable; this issue does not suggest turning rollup.rb or linebreak.rb into a general Bash parser.

Suggested regression coverage

  • ${#name} and ${#array[@]};
  • ${value#prefix} and ${value##prefix};
  • real inline comments still being removed;
  • hashes inside single- and double-quoted strings remaining unchanged;
  • generated output passing bash -n;
  • current bj.sh still regenerating byte-for-byte.

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 isn't workingbuildBuild and generation toolingmediumMedium priorityparser-followupCoverage exposes parser behavior needing separate work

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions