node-dashdash icon indicating copy to clipboard operation
node-dashdash copied to clipboard

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

Open DvdGiessen opened this issue 6 years ago • 1 comments

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 avatar Aug 01 '18 23:08 DvdGiessen

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. :)

DvdGiessen avatar Nov 26 '19 13:11 DvdGiessen