-
Notifications
You must be signed in to change notification settings - Fork 0
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
action: use bash ansi c quoting for JSON args to curl #4
Conversation
This _should_ help avoid issues where various types of quotes in `inputs.text` could cause problems when inserted into the JSON string we're building. Mashing strings together and pretending it's JSON is never going to be perfect, but this should be _more_ resilient than plain single quotes or double quotes. https://linux.die.net/man/1/bash#:~:text=Words%20of%20the%20form%20%24%27string%27%20are%20treated%20specially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice - looks great!
@@ -18,7 +18,7 @@ GitHub Action that posts a message to a Slack channel | |||
|
|||
### `text` | |||
|
|||
**Required** The message text to post | |||
**Required** The message text to post. See [Slack's documentation on formatting](https://api.slack.com/reference/surfaces/formatting#basic-formatting). Note that single quotes in your message *must* be escaped as `\'` due to how this input is consumed by bash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -41,7 +41,7 @@ runs: | |||
--header "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" \ | |||
--header "Content-Type: application/json; charset=utf-8" \ | |||
--url https://slack.com/api/chat.postMessage \ | |||
--data '{"channel": "${{ inputs.channel }}", "thread_ts": "${{ inputs.thread_ts }}", "unfurl_links": ${{ inputs.unfurl_links }}, "text": "${{ inputs.text }}"}' \ | |||
--data $'{"channel": "${{ inputs.channel }}", "thread_ts": "${{ inputs.thread_ts }}", "unfurl_links": ${{ inputs.unfurl_links }}, "text": "${{ inputs.text }}"}' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL - nice!
with: | ||
channel: ${{ env.SLACK_CHANNEL_ID }} | ||
thread_ts: ${{ steps.basic-message.outputs.ts }} | ||
text: "Test various text formatting:\n• Single quotes must be escaped \\' (b/c bash)\n• literal emoji 😀\n• colon-formatted emoji :blob-wave:\n• *bold text*\n• _italicized text_\n• ~strikethrough text~\n• `inline code`\n• Automatically linked text www.ynab.com\n• Link with <http://www.ynab.com|custom text>\n>Block quote\n```Multi-line\ncode```" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
This should help avoid issues where various types of quotes in
inputs.text
could cause problems when inserted into the JSON string we're building.Mashing strings together and pretending it's JSON is never going to be perfect, but this should be more resilient than plain single quotes or double quotes.
https://linux.die.net/man/1/bash#:~:text=Words%20of%20the%20form%20%24%27string%27%20are%20treated%20specially.