diff --git a/app/assets/javascripts/discourse/dialects/mention_dialect.js b/app/assets/javascripts/discourse/dialects/mention_dialect.js index b90b835ad57..7caced75ffb 100644 --- a/app/assets/javascripts/discourse/dialects/mention_dialect.js +++ b/app/assets/javascripts/discourse/dialects/mention_dialect.js @@ -39,6 +39,10 @@ Discourse.Dialect.on("register", function(event) { usernameIndex = remaining.indexOf(username), before = remaining.slice(0, usernameIndex); + // Break out if there is an uneven amount of backticks before + var backtickCount = before.split('`').length - 1; + if ((backtickCount % 2) === 1) { return; } + pattern.lastIndex = 0; remaining = remaining.slice(usernameIndex + username.length); diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index b272d4e4d9b..b4757545d38 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -132,6 +132,18 @@ test("Mentions", function() { "

foo bar baz @eviltrout

ohmagerd\nlook at this

", "does mentions properly with trailing text within a simple quote"); + cooked("`code` is okay before @mention", + "

code is okay before @mention

", + "Does not mention in an inline code block"); + + cooked("@mention is okay before `code`", + "

@mention is okay before code

", + "Does not mention in an inline code block"); + + cooked("don't `@mention`", + "

don't @mention

", + "Does not mention in an inline code block"); + }); test("Oneboxing", function() {