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

Fix completion log saving in current directory when program name contains certain characters #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DvdGiessen
Copy link

@DvdGiessen DvdGiessen commented Aug 1, 2018

Circumstances triggering the bug

While generating bash completion with dashdash through cmdln, I noticed that debugging logs for the completion were being written to my current directory. My program is called validana-cli, and the minus sign in that name causes my issue. This will happen for any program with a minus sign in the name; which is not uncommon for command line programs.

Analysis of the bug

Specifically, in dashdash debugging of completion is enabled by uncommenting a variable. This name of the variable contains the name of the program, I presume so that enabling completion debugging for a specific program won't cause many other programs using dashdash to start spewing out logfiles as well.

The problem is that if the program name contains a character that is not a valid character in a shell variable name (as in my case, the minus sign), the check the script uses will always succeed, and the filename it will use will be a combination of the last part of the program name and and a part of the broken variable name. Since this filename will also never contains any slashes, it will write this logfile to the current directory, spewing log files wherever the user goes and tries to use completion.

Proposed resolution

This pull request resolves this by using a function instead of a variable to store the filename for the debug log. Since functions names in bash are allowed a larger set of characters, this resolves the problem. It does so for all possible characters dashdash supports (if the program name would contain a character which is also not valid in a function name, most of the completion script would break anyway). It also keeps it just as simple as before to start debugging by just removing a single character.

Impact of changes

Since this change is only touching the bash_completion.in template file this change should not have any impact outside of the completion functionality. Since the changed code is specifically for debugging purposes and should never be triggered during normal use, impact on consumers of this package should be negligible.

Additional comments

@trentm If you decide to merge and publish this fix, could you also update your cmdln package to depend on the new version? That way users of that package (such as myself :) ) may also benefit from this fix.

@DvdGiessen
Copy link
Author

Ping @trentm any chance you could have a look at this pull request? I'm about to upgrade some packages that depend on cmdln and thus dashdash, and would like to include a fix for this issue. :)

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