Skip to content
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

ParameterExpansion does not allow empty substitution #51

Open
ghost opened this issue Apr 23, 2018 · 1 comment
Open

ParameterExpansion does not allow empty substitution #51

ghost opened this issue Apr 23, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 23, 2018

I seem to have found that the ParameterExpansion does not allow an empty substitution.

${parameter:-word}

If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

Example:

# test if var is was set before or not
if [ -z "${var:-}" ]; then
    var="var was not set before"
fi

Could you have look or tell me where i can change the grammar to allow an empty word, so i can make a pull request.

@parro-it
Copy link
Collaborator

It seems we are not handling empty string in parameter-expansion.js:

if (ret.expand) {
const bashParser = require('../../../index');
for (const prop of ret.expand) {
const ast = bashParser(ret[prop], {mode: 'word-expansion'});
ret[prop] = ast.commands[0].name;
}
delete ret.expand;
}

Since the value to substitute has to be further expanded, we recursively pass it to bash-parser (at the time I can't think of a better way).

When substituting with an empty string, we try to parse an empty string, and that fail. You can try
to change the code there and skip the parsing in this particular case.

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

No branches or pull requests

1 participant