Skip to content

Conversation

@erikvip
Copy link

@erikvip erikvip commented Jun 4, 2016

Error occurs when a space is in argument default values (or passed from command line too, I believe). This is because the value assignment is not quoted at all in the generated tmp file.

Also breaks when special characters (such as a single quote, double quote, any bash langauge specials) are in default values or passed.

Example code

#!/usr/bin/env bash
source "optparse.bash"
optparse.define short=d long=default-value-with-spaces desc="An argument which has spaces in it's default value" variable=DEFAULT_WITH_SPACES default="default value with spaces"
optparse.define short=s long=default-value-with-specials desc="An argument with a few special characters in it. A single quote should be handled ok" variable=DEFAULT_WITH_SPECIALS default="this is ' the !@#$%^&*( \${P\} special values" 

Output

$ ./test.sh
/tmp/optparse-19676.tmp: line 44: value: command not found
/tmp/optparse-19676.tmp: line 45: unexpected EOF while looking for matching `''
/tmp/optparse-19676.tmp: line 68: syntax error: unexpected end of file

Expected result

Should handle spaces & special characters gracefully, without throwing an error.

Fix

Easy fix, wrap assignment in quotes, and escape any quotes in the input. This fixes most special character use cases, better than nothing...

Pull request is on the way.

…capes) most special characters in default values. Fix merge conflict
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