Broken link formatting in Slack notifications
Summary
Commits containing [
and ]
aren't properly linkified to slacks link format <link|description>
, even though [[test] description](http://gitlab.com)
is valid markdown. This shows up in the 'failed pipeline' push message. The result (after stripping redundant fields/info) is something like:
Edit: Just noticed that the same happens for issues that are closed:
Curiously though, things do work when an issue is created: (I suspect this is because this is because the link is send separately in a title_link
field or so, so that slack is rendering the link instead of gitlab.)
Edit2: And another bug happens when the commit message contains a >
, which is then interpreted as the end of the link, so it should be escaped if possible:
Steps to reproduce
- Make a commit containing a pair of matching
[
and]
in it's description. - Trigger a pipeline on this commit. Make sure it fails or enable notifications on successful pipelines.
- Notice how the link to the commit isn't formatted correctly.
What is the current bug behavior?
The markdown [<commit description>](<commit url>)
is shown as-is on slack because gitlab doesn't transform it.
What is the expected correct behavior?
The text <commit description>
should be a link on its own.
Possible fixes
The string formatter is called here, but I'm not sure where the actual code is. Another fix would be to render commits the same as in the push notification: a linked hash followed by the plaintext commit description.
The package that handles the escaping explicitly states that the link name should be escaped here.
That will solve the issue with the extra >
, but not the issue with nested []
, as the library does not seem to handle that case. [
and ]
should be escaped anyhow because they could also appear separately in which case it's not valid markdown. This can be solved by substituting [
for \[
, ]
for \]
and \
for \\
in the link message.