FIX: Don't onebox links with labels unless the labels are the same as the URL

This commit is contained in:
Robin Ward 2013-09-06 16:46:55 -04:00
parent c996378fc0
commit a9f3489237
3 changed files with 13 additions and 0 deletions

View File

@ -10,6 +10,9 @@ var urlReplacerArgs = {
var url = matches[1],
displayUrl = url;
// If we improperly caught a markdown link abort
if (url.match(/\(http/)) { return; }
if (url.match(/^www/)) { url = "http://" + url; }
return ['a', {href: url}, displayUrl];
}

View File

@ -57,7 +57,12 @@ Discourse.Dialect.on("parseNode", function(event) {
if (path[i][0] === 'li') { return; }
}
// If the link has a different label text than the link itself, don't onebox it.
var label = node[node.length-1];
if (label !== node[1]['href']) { return; }
if (isOnOneLine(node, parent)) {
node[1]['class'] = 'onebox';
node[1].target = '_blank';

View File

@ -217,6 +217,11 @@ test("Oneboxing", function() {
ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links");
ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text");
ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed");
ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)",
"onebox"),
"Markdown links where the label is the same as the url are oneboxed");
cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street",
"<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\"" +
">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>",