From 98bb4c31a1eca362e6052075b12fa2dc5ab2a47d Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 4 Sep 2017 09:31:20 -0400 Subject: PLT-7473 Ignore text surrounded by multiple backquotes when parsing mentions (#7347) --- app/notification.go | 2 +- app/notification_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/notification.go b/app/notification.go index af7589934..b0a5d83ad 100644 --- a/app/notification.go +++ b/app/notification.go @@ -842,7 +842,7 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri var codeBlockPattern = regexp.MustCompile("(?m)^[^\\S\n]*\\`\\`\\`.*$[\\s\\S]+?(^[^\\S\n]*\\`\\`\\`$|\\z)") // Matches a backquote, either some text or any number of non-empty lines, and then a final backquote -var inlineCodePattern = regexp.MustCompile("(?m)\\`(?:.+?|.*?\n(.*?\\S.*?\n)*.*?)\\`") +var inlineCodePattern = regexp.MustCompile("(?m)\\`+(?:.+?|.*?\n(.*?\\S.*?\n)*.*?)\\`+") // Strips pre-formatted text and code blocks from a Markdown string by replacing them with whitespace func removeCodeFromMessage(message string) string { diff --git a/app/notification_test.go b/app/notification_test.go index ae6d0504a..02b6e1db0 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -382,7 +382,7 @@ func TestRemoveCodeFromMessage(t *testing.T) { t.Fatalf("received incorrect output\n\nGot:\n%v\n\nExpected:\n%v\n", actual, expected) } - input = "this is `not\n \ncode` because it has line with only whitespace" + input = "this is `not\n \ncode` because it has a line with only whitespace" expected = input if actual := removeCodeFromMessage(input); actual != expected { t.Fatalf("received incorrect output\n\nGot:\n%v\n\nExpected:\n%v\n", actual, expected) @@ -393,6 +393,12 @@ func TestRemoveCodeFromMessage(t *testing.T) { if actual := removeCodeFromMessage(input); actual != expected { t.Fatalf("received incorrect output\n\nGot:\n%v\n\nExpected:\n%v\n", actual, expected) } + + input = "these are ``multiple backquotes`` around code" + expected = "these are around code" + if actual := removeCodeFromMessage(input); actual != expected { + t.Fatalf("received incorrect output\n\nGot:\n%v\n\nExpected:\n%v\n", actual, expected) + } } func TestGetMentionKeywords(t *testing.T) { -- cgit v1.2.3-1-g7c22