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

Whitespace in filename results in no file found #118

Open
BasPH opened this issue Sep 14, 2021 · 1 comment
Open

Whitespace in filename results in no file found #118

BasPH opened this issue Sep 14, 2021 · 1 comment

Comments

@BasPH
Copy link

BasPH commented Sep 14, 2021

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.

@polarathene
Copy link

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:

IFS=', ' read -r -a FILELIST <<< "$FILE_PATH"

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 😅 )

You were referencing back in Sep 2021:

FIND_CALL+=("${i}")
COMMAND="${FIND_CALL[*]}"
$COMMAND &>> error.txt || true
unset 'FIND_CALL[${#FIND_CALL[@]}-1]'

Where those lines numbers now reference:

mapfile -t FILE_ARRAY < <( git diff --name-only --diff-filter=AM "$MASTER_HASH" )
for i in "${FILE_ARRAY[@]}"
do

So this line is the problem:

COMMAND="${FIND_CALL[*]}"

* 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.

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

2 participants