FIX: Protocol-less links that begin with a shouldn't error

This commit is contained in:
Robin Ward 2016-07-20 13:44:12 -04:00
parent 16383a1749
commit b9177af1eb
2 changed files with 6 additions and 3 deletions

View File

@ -114,10 +114,12 @@ export function setup(helper) {
replaceBBCode('url', contents => {
if (!Array.isArray(contents)) { return; }
if (contents.length === 1 && contents[0][0] === 'a') {
const first = contents[0];
if (contents.length === 1 && Array.isArray(first) && first[0] === 'a') {
// single-line bbcode links shouldn't be oneboxed, so we mark this as a bbcode link.
if (typeof contents[0][1] !== 'object') { contents[0].splice(1, 0, {}); }
contents[0][1]['data-bbcode'] = true;
if (typeof first[1] !== 'object') { first.splice(1, 0, {}); }
first[1]['data-bbcode'] = true;
}
return ['concat'].concat(contents);
});

View File

@ -551,6 +551,7 @@ test('basic bbcode', function() {
test('urls', function() {
cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url");
cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a");
cookedPara("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without parameter");
cookedPara("[url=http://example.com]example[/url]", "<a href=\"http://example.com\">example</a>", "supports [url] with given href");
cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]",