Skip to content

Commit

Permalink
fix: sanitization error with sub-shells (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRibeiro authored Jan 13, 2023
1 parent 8baf6e1 commit 8fd1c99
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,42 @@ jobs:
}
]
}
- run:
name: Export value to file
command: |
printf '%s\n' "Hello There!" > /tmp/msg
- slack/notify:
debug: true
step_name: "Notify with custom message coming from sub-shell and template variable"
event: always
custom: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Current Job: $CIRCLE_JOB"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "$(cat /tmp/msg)"
}
}
]
}
- slack/notify:
debug: true
step_name: "Notify with only custom message coming from sub-shell"
event: always
custom: |
{
"type": "mrkdwn",
"text": "$(cat /tmp/msg)"
}
workflows:
test-deploy:
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ SanitizeVars() {

# Extract the variable names from the matches.
local variable_names
variable_names="$(printf '%s\n' "$variables" | grep -o -E '[a-zA-Z0-9_]+')"
variable_names="$(printf '%s\n' "$variables" | grep -o -E '[a-zA-Z0-9_]+' || true)"
[ -z "$variable_names" ] && { printf '%s\n' "Nothing to sanitize."; return 0; }

# Find out what OS we're running on.
detect_os
Expand Down

0 comments on commit 8fd1c99

Please sign in to comment.