bashlex icon indicating copy to clipboard operation
bashlex copied to clipboard

Fails with nested use of backquotes

Open rpmoseley opened this issue 1 year ago • 2 comments

If you try to parse the following command:

suser=expr "\id`" : '(uid=0)(.) .'`

this will fail with the following exception:

bashlex.tokenizer.MatchedPairError: unexpected EOF while looking for matching '"' (position 7)

After some investigation, it was found to be the adjustment made when a backquote is found within the function '_stringextract' in module 'subst.py', it will incorrectly only skip the backquote itself, not the following character as well.

The simple solution is to increment the variable by 2 instead of 1, this will then handle the parsing correctly.

rpmoseley avatar Nov 13 '24 07:11 rpmoseley

Hi, thanks for the report. Do you mind sending a pull request, with a few tests?

idank avatar Nov 13 '24 09:11 idank

Hi, apologies for the time take to get back to you. I have been spending some time, deciding whether to make changes to ensure that the AST produced by backquotes is the same as is currently done for the use of $(...) before submitting the pull request. Also, I'm having trouble getting the test to pass, it seems to think that there are differences even though the AST looks correct to me.

rpmoseley avatar Nov 18 '24 11:11 rpmoseley