yhatt / jsx-slack

Build JSON object for Slack Block Kit surfaces from JSX
https://jsx-slack.netlify.app/
MIT License
467 stars 16 forks source link

Preserve URLs in links #289

Closed nholden closed 1 year ago

nholden commented 1 year ago

In https://github.com/yhatt/jsx-slack/issues/288, @mrcljx pointed out that characters in link URLs that are already escaped get escaped again. For example:

<a href="https://google.com/a?x=y%3Az">show</a>

is encoded as

<https://google.com/a?x=y%253Az|show>

This PR removes implicit encoding from link URLs. Following @yhatt's recommendation, it ensures we continue to escape characters that Slack reserves. &, <, and > are replaced by corresponding HTML entities, and we continue to use urlEncode to escape |.

closes https://github.com/yhatt/jsx-slack/issues/288

yhatt commented 1 year ago

Thank you for your contribution :smile:

The hyperlink with date formatting still has implicit URI encoding.

<a href="https://example.com/?x=y%3Az">
  <time datetime={1234567890}>{'test: {date_short}'}</time>
</a>
<!date^1234567890^test: {date_short}^https://example.com/?x=y%253Az|test: Feb 13, 2009>

In addition, ^ also should escape in the link with date formatting. If not, a hyperlink will truncate raw ^ character and after chars.

nholden commented 1 year ago

Thanks, @yhatt! Great catch.

I took a stab at addressing that in https://github.com/yhatt/jsx-slack/pull/289/commits/efed184da3ea7a66395509ccc8edbe05c8623a70. Looks good in the Block Kit Builder, but I'm open to other approaches!