Skip to content

Commit

Permalink
Merge pull request #7 from DanielVoogsgerd/word_splitting
Browse files Browse the repository at this point in the history
fix: Prevent word-splitting in user input
  • Loading branch information
thekaveman authored Oct 28, 2021
2 parents 25d1222 + 8656017 commit 16bae86
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions conventional-pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env bash

# list of Conventional Commits types
cc_types="feat fix"
default_types="build chore ci docs $cc_types perf refactor revert style test"
types=( $cc_types )
cc_types=("feat" "fix")
default_types=("build" "chore" "ci" "docs" "${cc_types[@]}" "perf" "refactor" "revert" "style" "test")
types=( "${cc_types[@]}" )

if [ $# -eq 1 ]; then
types=( $default_types )
types=( "${default_types[@]}" )
else
# assume all args but the last are types
while [ $# -gt 1 ]; do
types+=( $1 )
types+=( "$1" )
shift
done
fi

# the commit message file is the last remaining arg
msg_file=$1
msg_file="$1"

# join types with | to form regex ORs
r_types="($(IFS='|'; echo "${types[*]}"))"
Expand All @@ -34,7 +34,7 @@ if grep -Eq "$pattern" "$msg_file"; then
exit 0
fi

echo "[Commit message] $( cat $msg_file )"
echo "[Commit message] $( cat "$msg_file" )"
echo "
Your commit message does not follow Conventional Commits formatting
https://www.conventionalcommits.org/
Expand Down

0 comments on commit 16bae86

Please sign in to comment.