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


(Wladimir Palant) #1

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”.


(Eli the Bearded) #2

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


(Wladimir Palant) #3

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.


(Robin Ward) #4

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


(Robin Ward) #5

Thanks for reporting it - here’s a fix:


(Robin Ward) #6