Skip to content

Commit b490468

Browse files
Fix shelldre:S7688 on hook-templates by replacing [] test command with [[]] (#47)
1 parent 4103cfb commit b490468

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/bootstrap/hook-templates.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ stdin_data=$(cat)
3838
# Extract tool_name and file_path using sed (no jq dependency)
3939
tool_name=$(echo "$stdin_data" | sed -n 's/.*"tool_name":"\([^"]*\)".*/\1/p' | head -1)
4040
41-
if [ "$tool_name" != "Read" ]; then
41+
if [[ "$tool_name" != "Read" ]]; then
4242
exit 0
4343
fi
4444
4545
# Extract file_path from tool_input
4646
file_path=$(echo "$stdin_data" | sed -n 's/.*"tool_input":\s*{\([^}]*\)}.*/\1/p' | \
4747
sed -n 's/.*"file_path":"\([^"]*\)".*/\1/p' | head -1)
4848
49-
if [ -z "$file_path" ] || [ ! -f "$file_path" ]; then
49+
if [[ -z "$file_path" ]] || [[ ! -f "$file_path" ]]; then
5050
exit 0
5151
fi
5252
5353
# Scan file for secrets
5454
sonar analyze --file "$file_path" > /dev/null 2>&1
5555
exit_code=$?
5656
57-
if [ $exit_code -eq 51 ]; then
57+
if [[ $exit_code -eq 51 ]]; then
5858
# Secrets found - deny file read
5959
reason="Sonar detected secrets in file: $file_path"
6060
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"$reason\"}}"
@@ -131,7 +131,7 @@ stdin_data=$(cat)
131131
# Extract prompt field using sed
132132
prompt=$(echo "$stdin_data" | sed -n 's/.*"prompt":"\([^"]*\)".*/\1/p' | head -1)
133133
134-
if [ -z "$prompt" ]; then
134+
if [[ -z "$prompt" ]]; then
135135
exit 0
136136
fi
137137
@@ -145,7 +145,7 @@ echo -n "$prompt" > "$temp_file"
145145
sonar analyze --file "$temp_file" > /dev/null 2>&1
146146
exit_code=$?
147147
148-
if [ $exit_code -eq 51 ]; then
148+
if [[ $exit_code -eq 51 ]]; then
149149
# Secrets found - block prompt
150150
reason="Sonar detected secrets in prompt"
151151
echo "{\"decision\":\"block\",\"reason\":\"$reason\"}"

0 commit comments

Comments
 (0)