idank / bashlex

Python parser for bash
GNU General Public License v3.0
550 stars 94 forks source link

Fix assignment, variable name can be alpha numeric #46

Closed sereysethy closed 4 years ago

idank commented 5 years ago

Thanks for the change.

This function is based on http://git.savannah.gnu.org/cgit/bash.git/tree/general.c?id=df2c55de9c87c2ee8904280d26e80f5c48dd6434#n263

Can you make sure the change you're making is correct with respect to how Bash handles this?

Also, can you please add a test?

Thanks!

sereysethy commented 5 years ago

I verified in the bash source code, here it is the comment that I found:

/* Variable names in assignment statements may contain only letters,
     digits, and `_'. */

So variable name can be letters, digits and _. I also added a test case, the test passes. Please check.

idank commented 5 years ago

I think this will also accept variable names that start with a digit, no?

sereysethy commented 5 years ago

No, you cannot have variables starting with a digit, this will have a conflict with the reserved parameters (positional parameters) passed to a script or a function ${N} where N is digit.

idank commented 5 years ago

Doesn't your change allow that?