# Onebox embeds too much content when target page has malformed HTML

**URL:** https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193
**Category:** Feature
**Created:** [October 16, 2014, 12:48pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193 "2014-10-16T12:48:50Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![twicedd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/twicedd/32/121201_2.png) [@twicedd](https://meta.discourse.org/u/twicedd)
#### Post date: [October 16, 2014, 12:48pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/1 "2014-10-16T12:48:51Z")

</div>

Hi,

I had an issue with the following link: [Le charlatanisme de Galuel | ⊔Foundation](http://cupfoundation.wordpress.com/2014/10/13/le-charlatanisme-de-galuel/)

Put on a one-line, it almost imports the whole page. I think this is not a normal behaviour, isn’t it?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [October 16, 2014, 1:27pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/2 "2014-10-16T13:27:17Z")

</div>

This is indeed really weird, the preview of the onebox is completely different than the _cooked_ version…

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 16, 2014, 10:00pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/3 "2014-10-16T22:00:32Z")

</div>

We have seen this before, it implies badly invalid markup on the target site which somehow confuses the oneboxer, that is what I recall.

---

<div class="post-metadata">

### Author: ![twicedd](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/twicedd/32/121201_2.png) [@twicedd](https://meta.discourse.org/u/twicedd)
#### Post date: [October 20, 2014, 10:03am UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/4 "2014-10-20T10:03:47Z")

</div>

So what should we do about it?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 20, 2014, 2:49pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/5 "2014-10-20T14:49:53Z")

</div>

See if the target site passes html validation via the w3c validator, and if not, how many errors does it report?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [October 20, 2014, 11:33pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/6 "2014-10-20T23:33:19Z")

</div>

[Error Line 1250, Column 113: Stray end tag a.](http://validator.w3.org/check?uri=http%3A%2F%2Fcupfoundation.wordpress.com%2F2014%2F10%2F13%2Fle-charlatanisme-de-galuel%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.3+http%3A%2F%2Fvalidator.w3.org%2Fservices)

```
…s://fr.wordpress.com/?ref=lof">Build a website with WordPress.com</a></a></div>

```

Yep, that’ll mess up the document structure.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 21, 2014, 12:26am UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/7 "2014-10-21T00:26:35Z")

</div>

Not sure how to fix this. Can we make onebox more tolerant of screwed up HTML?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 21, 2014, 12:32am UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/8 "2014-10-21T00:32:04Z")

</div>

We can, nokogiri can iron out bad html and we can trucate it at some sort of sane size.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 21, 2014, 12:32am UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/9 "2014-10-21T00:32:49Z")

</div>

@techapj can you add this to your list?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [March 23, 2016, 11:15am UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/10 "2016-03-23T11:15:38Z")

</div>

This is now fixed via:

[https://github.com/discourse/onebox/commit/1b8bef8f96a4353cdfa6bc67da87d6750d5d31bf](https://github.com/discourse/onebox/commit/1b8bef8f96a4353cdfa6bc67da87d6750d5d31bf)

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [March 23, 2016, 11:16am UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/11 "2016-03-23T11:16:03Z")

</div>



---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [February 17, 2021, 5:30pm UTC](https://meta.discourse.org/t/onebox-embeds-too-much-content-when-target-page-has-malformed-html/21193/12 "2021-02-17T17:30:10Z")

</div>

Here’s how it looks now 👍

> **[Le charlatanisme de Galuel](https://cupfoundation.wordpress.com/2014/10/13/le-charlatanisme-de-galuel/)**
>
> Les vidéos youTube permettent à chacun d’exprimer librement toute idée, toute théorie, même les plus farfelues. C’est plutôt un progrès démocratique à l’époque du numérique. Il n&…
