Skip to content

Commit

Permalink
Protect code against cyclic dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
whoan committed Nov 9, 2019
1 parent 8a36ef1 commit 5b1497e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions snip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ __snip__replace_snips() {
return
fi

if (( ++__snip_replacements > 20 )); then
echo "Too many snip replacements." >&2
echo "Please check your code for cyclic dependencies or open an issue: https://github.com/whoan/snip/issues/new" >&2
return 1
fi

local filename=${source_file##*/}
local root_filename="${filename%.*}"
local extension="${filename#"$root_filename"}"
Expand Down Expand Up @@ -187,6 +193,7 @@ __snip() {
# only valid files are processed
local param="${params[$i]}"
if __snip__is_text_file "$param"; then
__snip_replacements=0
params[$i]=$(__snip__replace_snips "$param" $force) || return 1
fi
done
Expand Down

0 comments on commit 5b1497e

Please sign in to comment.