Skip to content

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:

2019-08-26-105319_399x87_scrot

Edit: Just noticed that the same happens for issues that are closed:

2019-08-27-010301_667x80_scrot

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.)

2019-08-27-010856_415x43_scrot

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:

2019-08-29-172215_753x240_scrot

Steps to reproduce

  1. Make a commit containing a pair of matching [ and ] in it's description.
  2. Trigger a pipeline on this commit. Make sure it fails or enable notifications on successful pipelines.
  3. 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.

Edited by Ragnar Groot Koerkamp