mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
FIX: @mentions should not be processed within links
This commit is contained in:
@ -10,7 +10,6 @@ var urlReplacerArgs = {
|
|||||||
var url = matches[1],
|
var url = matches[1],
|
||||||
displayUrl = url;
|
displayUrl = url;
|
||||||
|
|
||||||
|
|
||||||
// Don't autolink a markdown link to something
|
// Don't autolink a markdown link to something
|
||||||
if (url.match(/\]\[\d$/)) { return; }
|
if (url.match(/\]\[\d$/)) { return; }
|
||||||
|
|
||||||
|
@ -20,3 +20,20 @@ Discourse.Dialect.inlineRegexp({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// We have to prune @mentions that are within links.
|
||||||
|
Discourse.Dialect.on("parseNode", function(event) {
|
||||||
|
var node = event.node,
|
||||||
|
path = event.path;
|
||||||
|
|
||||||
|
if (node[1] && node[1]["class"] === 'mention') {
|
||||||
|
var parent = path[path.length - 1];
|
||||||
|
// If the parent is an 'a', remove it
|
||||||
|
if (parent && parent[0] === 'a') {
|
||||||
|
var username = node[2];
|
||||||
|
node.length = 0;
|
||||||
|
node[0] = "__RAW";
|
||||||
|
node[1] = username;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
@ -185,6 +185,14 @@ test("Mentions", function() {
|
|||||||
"<p>Hello <a class=\"mention\" href=\"/users/sam\">@sam</a></p>",
|
"<p>Hello <a class=\"mention\" href=\"/users/sam\">@sam</a></p>",
|
||||||
"translates mentions to links");
|
"translates mentions to links");
|
||||||
|
|
||||||
|
cooked("[@codinghorror](https://twitter.com/codinghorror)",
|
||||||
|
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
|
||||||
|
"it doesn't do mentions within links");
|
||||||
|
|
||||||
|
cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue,
|
||||||
|
"<p><a href=\"https://twitter.com/codinghorror\">@codinghorror</a></p>",
|
||||||
|
"it doesn't do link mentions within links");
|
||||||
|
|
||||||
cooked("Hello @EvilTrout", "<p>Hello <span class=\"mention\">@EvilTrout</span></p>", "adds a mention class");
|
cooked("Hello @EvilTrout", "<p>Hello <span class=\"mention\">@EvilTrout</span></p>", "adds a mention class");
|
||||||
cooked("robin@email.host", "<p>robin@email.host</p>", "won't add mention class to an email address");
|
cooked("robin@email.host", "<p>robin@email.host</p>", "won't add mention class to an email address");
|
||||||
cooked("hanzo55@yahoo.com", "<p>hanzo55@yahoo.com</p>", "won't be affected by email addresses that have a number before the @ symbol");
|
cooked("hanzo55@yahoo.com", "<p>hanzo55@yahoo.com</p>", "won't be affected by email addresses that have a number before the @ symbol");
|
||||||
|
Reference in New Issue
Block a user