anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.62k stars 129 forks source link

Associative array assignment is quoted incorrectly #31

Closed jlucktay closed 4 years ago

jlucktay commented 4 years ago

Firstly, thank you very much for shellharden!

I have a small issue that is happening with version 4.1.1.

My (not properly quoted) line begins in this state:

SERVER_LOCATIONS[$location]="$zone"

shellharden --check --replace changes it to:

SERVER_LOCATIONS["$location]=$zone"

with quotes only in front of the subscript and at the end of the value being assigned.

It should be changing it to something like this instead:

SERVER_LOCATIONS["$location"]="$zone"

to fully quote both the subscript and the value.

anordal commented 4 years ago

Excellent report.

I think your line was fine, though. The right side of the assignment is already exempt from quoting, and it appears to me that so should the left.

What happened here is that the assignment was not recognized as such, and therefore got quoted as a command. Commands and arguments undergo what I have called "holistic quoting" (c991eeaf), new in version 2. So this bug is old. But those versions are not fixable the same way, because the recognition of assignments was the big thing in version 4.

I'm fixing this by accepting any amount of quoting also for this type of assignment.