Skip to content

bug-666: #870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

bug-666: #870

wants to merge 2 commits into from

Conversation

phidebian
Copy link

TLDR;

  • src/cmd/ksh93/include/shlex.h Implement yet another lex state funcalias, set to 1 when
    function keyword is an alias expansion.

  • src/cmd/ksh93/sh/lex.c Allow alias expansion on word following a 'function ' expansion.

  • src/cmd/ksh93/tests/alias.sh Update alias.sh to catch alias x='function ' failure.

Explanations:
Alias allows aliases to be chained while expanded alias value have a trailing space.

Assuming
alias 'x=function ' y=f

Parsing
x y { echo :); }

x is a simple cmd, a check for alias is done and is successfull we got 'function '
The parser then then enter funct() for parsing a function, the next token fetch is not a simple cmd anymore, no check for alias will be done, next token is then y and become the function name.

To fix this, when expanding to 'function ' we need to setup a lexer state, I called it funcalias in shlex.c, it is then set to 1 in sh_lex()
When funct() parse y { ... the funcalias==1 allows a check for alias, we then get the 'f' expansion and reset funcalias. At this point other alias expansion are permitted, though hard to follow.

$ alias 'x=function ' y=f z='{ ' t='echo ' u='AA ' v='}' $ x y z t u v
$ f
AA

TLDR;
- src/cmd/ksh93/include/shlex.h
  Implement yet another lex state funcalias, set to 1 when function
  keyword is an alias expansion.
- src/cmd/ksh93/sh/lex.c
  Allow alias expansion on word following a 'function ' expansion.
- src/cmd/ksh93/tests/alias.sh
  Update alias.sh to catch alias x='function ' failure.

Explanations:
Alias allows aliases to be chained while expanded alias value has a trailing
space.

Assuming
alias 'x=function ' y=f

Parsing
x y { echo :\); }

x is a simple cmd, a check for alias is done and is successfull we got
'function '
The parser then then enter funct() for parsing a function, the nex
token fetch is not a simple cmd anymore, no check for alias will be
done, next token is then y and become the function name.

To fix this, when expanding to 'function ' we need to setup a lexer
state, I called it funcalias in shlex.c, it is then set to 1 in
sh_lex()
When funct() parse y { ... the funcalias==1 allows a check for alias,
we then get the 'f' expansion and reset funcalias.
At this point other alias expansion are permitted, though hard to
follow.

$ alias 'x=function ' y=f z='{ ' t='echo ' u='AA '  v='}'
$ x y z t u v
$ f
AA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant