anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.63k stars 130 forks source link

added quotation marks break variable declaration #39

Closed LucasLarson closed 3 years ago

LucasLarson commented 3 years ago

If I save example.sh with this content:

export variable=${one:-${two}}

and run shellharden --replace -- example.sh, its content is changed to this:

export variable="${one:-${two}"}

instead of perhaps this:

export variable="${one:-${two}}"

or keeping the right side without quotation marks:

export variable=${one:-${two}} # no change from input

I was able to reproduce this using shellharden 4.1.2 on Ubuntu 20.10’s GNOME Terminal 3.38 and macOS 11.3’s Terminal 2.11 and iTerm2 3.4

anordal commented 3 years ago

Very well reported.

There are two aspects of this that need fixing:

  1. This curly brace parsing is not recursive. I'm only surprised that I got away with this for so long.
  2. The statement is not recognised as an assignment, because export is not on the list of those keywords (together with declare, local and readonly). I fail to remember if this was an oversight. This would allow not quoting the right side.

Workaround:

In this case, you may drop the inner curly braces, since they are not significant.