github-action-markdown-link-check icon indicating copy to clipboard operation
github-action-markdown-link-check copied to clipboard

Whitespace in filename results in no file found

Open BasPH opened this issue 2 years ago • 1 comments

I have a project with a whitespace in the filename. This results in a rather useless error "ERROR: File not found! Please provide a valid filename as an argument.". After digging, it turns out https://github.com/tcort/markdown-link-check tries reading the filename up to the whitespace, so excluding everything after. Code where the filename is provided is here: https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/master/entrypoint.sh#L171-L174.

I couldn't get it to work, so reporting an issue for the moment.

BasPH avatar Sep 14 '21 10:09 BasPH

First off, it's better to copy a permalink (click on the ... in the line sidebar), so that when issues like this go without interaction for so long, one does not need to go into git blame to make sure you're still referencing the same lines/content (might have changed since). Here's the permalink.


Example with dummy lines:

#! /bin/bash

mapfile -t FILE_ARRAY < <(printf "%s\n" 'words with spaces' 'more words' 'word' )
for i in "${FILE_ARRAY[@]}"
do
  echo "VALUE: ${i}"
done

# Output:
VALUE: words with spaces
VALUE: more words
VALUE: word

You can use the existing git command to get a diff with paths that also have spaces and will find the same sort of behaviour. No bug there.

The command to collect files from a diff though... git diff --name-only --diff-filter=AM "$MASTER_HASH" seems like it could be an issue. In my own testing, if you have new commits on master since you branched off a commit for a PR, the diff to master includes changes from master (new files added or changed since), which may be misleading. If those files don't exist on the PR branch being checked, then a file would not be found too.

I haven't reviewed the whole script file, but your particular issue was probably due to earlier logic:

https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/228fbf4ffb2a86a65314866e9b2322b519fd885f/entrypoint.sh#L71

IFS=', ' isn't reliable here AFAIK, it will split the input into array items at , OR , not the combined pair sequence of , that seems intended. That will result in file paths with spaces being split accidentally:

IFS=', ' read -r -a FILELIST <<< 'words with spaces,more words, word'
for i in "${FILELIST[@]}"
do
  echo "VALUE: ${i}"
done

# Output:
VALUE: words
VALUE: with
VALUE: spaces
VALUE: more
VALUE: words
VALUE: word

EDIT: Nope, my bad, I added a link to docs for that feature. I didn't focus on the lines you referenced, as they had been shifted (hence the value of permalink :sweat_smile: )

You were referencing back in Sep 2021:

https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/7a77bd14ccf35078a808d92fde3e60d6947bb6a3/entrypoint.sh#L171-L174

Where those lines numbers now reference:

https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/228fbf4ffb2a86a65314866e9b2322b519fd885f/entrypoint.sh#L171-L174

So this line is the problem:

https://github.com/gaurav-nelson/github-action-markdown-link-check/blob/228fbf4ffb2a86a65314866e9b2322b519fd885f/entrypoint.sh#L177

* expanding the array contents into a single string value to call as a command.. Instead it could just be

COMMAND="${FIND_CALL[*]}"
$COMMAND "${i}" &>> error.txt || true

That will keep the array value quote wrapped, no need to append to the FIND_CALL array, and then unset with each iteration.

polarathene avatar Jun 23 '22 08:06 polarathene