FIX: Work with phpBB import style links with ellipsis

This commit is contained in:
Robin Ward 2014-07-14 14:26:48 -04:00
parent 42dcb77d93
commit 1886ffaff2
4 changed files with 25 additions and 23 deletions

View file

@ -1,13 +0,0 @@
// prevent XSS
Discourse.Dialect.on('parseNode', function (event) {
var node = event.node;
if (node[0] === 'a') {
var attributes = node[1];
if (attributes["href"]) {
if (!Discourse.Markdown.urlAllowed(attributes["href"])) {
delete attributes["href"];
}
}
}
});

View file

@ -0,0 +1,21 @@
Discourse.Dialect.on('parseNode', function (event) {
var node = event.node,
path = event.path;
if (node[0] === 'a') {
// It's invalid HTML to nest a link within another so strip it out.
for (var i=0; i<path.length; i++) {
if (path[i][0] === 'a') {
var parent = path[path.length - 1],
pos = parent.indexOf(node);
// Just leave the link text
if (pos !== -1) {
parent[pos] = node[2];
}
return;
}
}
}
});

View file

@ -182,16 +182,6 @@ Discourse.Markdown = {
if(/^mailto:[\w\.\-@]+/i.test(url)) { return url; }
},
/**
Checks to see if a name, class or id is allowed in the cooked content
@method nameIdClassAllowed
@param {String} tagName to check
@param {String} attribName to check
@param {String} value to check
**/
/**
Sanitize text using the sanitizer

View file

@ -142,6 +142,10 @@ test("Links", function() {
"It does not consider references that are obviously not URLs");
cooked("<small>http://eviltrout.com</small>", "<p><small><a href=\"http://eviltrout.com\">http://eviltrout.com</a></small></p>", "Links within HTML tags");
cooked("[http://google.com ... wat](http://discourse.org)",
"<p><a href=\"http://discourse.org\">http://google.com ... wat</a></p>",
"it supports linkins within links");
});
test("simple quotes", function() {