[MM-48860] / [GH-21863] Change regex to reduce false positive transforms on incoming webhook text (#21852)

* Change regex to reduce false positive transforms on incoming webhook text

Adds an additional condition to the 2nd capture group to ensure we don't match another `|` char

See https://github.com/mattermost/mattermost-server/issues/21800 for details

* Add test per suggested comment (switch Pi-hole URL out for Mattermost one 😉)

Signed-off-by: Adam Warner <me@adamwarner.co.uk>

---------

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Saturnino Abril <saturnino.abril@gmail.com>
Этот коммит содержится в:
Adam Warner
2023-12-06 19:12:31 +00:00
коммит произвёл GitHub
родитель a24ef3f07d
Коммит 3fe68e73bf
2 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@@ -264,7 +264,7 @@ func SplitWebhookPost(post *model.Post, maxPostSize int) ([]*model.Post, *model.
func (a *App) CreateWebhookPost(c request.CTX, userID string, channel *model.Channel, text, overrideUsername, overrideIconURL, overrideIconEmoji string, props model.StringInterface, postType string, postRootId string) (*model.Post, *model.AppError) {
// parse links into Markdown format
linkWithTextRegex := regexp.MustCompile(`<([^\n<\|>]+)\|([^\n>]+)>`)
linkWithTextRegex := regexp.MustCompile(`<([^\n<\|>]+)\|([^\|\n>]+)>`)
text = linkWithTextRegex.ReplaceAllString(text, "[${2}](${1})")
post := &model.Post{UserId: userID, ChannelId: channel.Id, Message: text, Type: postType, RootId: postRootId}