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

Bug: Filenames with spaces are treated as multiple arguments which generate file not found errors #71

Open
jamesquilty opened this issue Sep 16, 2020 · 0 comments

Comments

@jamesquilty
Copy link

jamesquilty commented Sep 16, 2020

I tried activating the markdownlint hook for my repo, which runs without complaint with mdl . but with the pre-commit hook mdl crashed on some calls with a cryptic multi-line traceback which appears to be saying "File not found: ."

The problem appears to be that, while pre-commit correctly quotes filenames containing spaces when passing them as arguments to the hook script, the run-mdl Ruby script assumes that there are no spaces in the arguments and joins them all together with no quoting or escaping with args = ARGV.join(' ') and then calls mdl #{args} 2>&1. Cryptic tracebacks ensue.

I don't know Ruby, but the alternatives for fixing this are fairly clear:

  1. Use the shellescape builtin with something like ARGV.shellescape.join(' ') (I'm only speculating that this will function as desired in Ruby), or
  2. Iterate over each element of ARGV, running mdl on each and managing $CHILD_STATUS.exitstatus within the loop.

This is a blocker for me, I can't activate this hook if it can't handle filenames which contain spaces.

Other places where this construct is used may be seen via a search for ARGV.join(' ') within this repo.

Related: puts "args: #{args}" is handled inconsistently within the scripts. I agree with the comment and conditional seen in run-fasterer, run-reek and run-rubocop:

# ... pre-commit looks better if there is no output on success.
...
puts args if ENV['DEBUG']

It would be... better... if argument printing in all these scripts were harmonized to use puts "args: #{args}" if ENV['DEBUG'] (or whatever works, if my speculation about Ruby syntax is incorrect).

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