Skip to content
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

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

dbertram
Copy link
Member

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.

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.
Copy link
Member

@bradymholt bradymholt left a 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.
Copy link
Member

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 }}"}' \
Copy link
Member

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```"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@dbertram dbertram merged commit cc28fe6 into main Nov 26, 2024
1 check passed
@dbertram dbertram deleted the db/text-quoting branch November 26, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants