Some BBCode URLs cannot be handled (contents[0].splice is not a function)

The following BBCode will currently produce an exception (reproduced on try.discourse.org):

[url]abc.com[/url]

The error message in production is “TypeError: e[0].splice is not a function” - this refers to app/assets/javascripts/discourse/dialects/bbcode_dialect.js, the Discourse.BBCode.replaceBBCode('url', ...) block there. It seems that contents[0] is a string but the code attempts to treat it as an array. I didn’t find all the pieces creating this variable, but for some reason this only appears to be an issue if the URL starts with a lower-case letter “a”.

2 Likes

Shouldn’t the URL start with a scheme, like http:// or https://?

Yes, they should. However, some posts in our phpBB forum go without a scheme - I guess that some older phpBB version accepted those. Discourse will normally treat these correctly (namely by not linkifying them) - unless the content starts with the lowercase “a” as mentioned here. The other issue are links with the abp:// scheme which are relatively common in our forum - these cause Discourse to break as well.

1 Like

We should also never allow markup to raise a javascript error. I’ll be fixing this one!

5 Likes

Thanks for reporting it - here’s a fix:

5 Likes