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

**URL:** https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089
**Category:** Bug
**Created:** [July 11, 2016, 12:21pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089 "2016-07-11T12:21:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![palant](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/palant/32/104531_2.png) [@palant](https://meta.discourse.org/u/palant)
#### Post date: [July 11, 2016, 12:21pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089/1 "2016-07-11T12:21:39Z")

</div>

The following BBCode will currently produce an exception (reproduced on [try.discourse.org](http://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”.

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [July 11, 2016, 5:12pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089/2 "2016-07-11T17:12:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![palant](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/palant/32/104531_2.png) [@palant](https://meta.discourse.org/u/palant)
#### Post date: [July 11, 2016, 8:00pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089/3 "2016-07-11T20:00:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [July 11, 2016, 9:00pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089/4 "2016-07-11T21:00:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [July 20, 2016, 5:44pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089/5 "2016-07-20T17:44:51Z")

</div>

Thanks for reporting it - here’s a fix:

[https://github.com/discourse/discourse/commit/b9177af1eb21d6132e131388f55115252e296620](https://github.com/discourse/discourse/commit/b9177af1eb21d6132e131388f55115252e296620)

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [July 20, 2016, 5:44pm UTC](https://meta.discourse.org/t/some-bbcode-urls-cannot-be-handled-contents-0-splice-is-not-a-function/47089/6 "2016-07-20T17:44:55Z")

</div>


