# Vimeo embed URLs parsed incorrectly in email

**URL:** https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042
**Category:** Bug
**Created:** [June 24, 2022, 5:56pm UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042 "2022-06-24T17:56:20Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [June 24, 2022, 5:56pm UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/1 "2022-06-24T17:56:21Z")

</div>

Vimeo provides two types of urls: direct links (`https://vimeo.com/508864124/fcbbcc92fa`) and embed links (which can be used in an iframe, but won’t work if clicked directly)

For example:

```plaintext
<iframe src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>

```

1. When this is sent as a notification email, the direct link appears correctly, but the iframe is replaced into a link with the wrong URL: `https://vimeo.com/508864124?h=fcbbcc92fa` instead of `https://player.vimeo.com/video/508864124?h=fcbbcc92fa`

2. Is there a way to bypass the iframe-to-URL conversion altogether? Just like we already do with polls, it says something like “Click here to see the poll”

---

<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: [June 27, 2022, 8:04am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/2 "2022-06-27T08:04:19Z")

</div>

Tricky, we have some special magic to amend how we remap cooked for email processes we can clean up, for sure.

Will put a #pr-welcome for now and consider further prioritization if this pops ups a few more times.

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [June 27, 2022, 10:07am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/3 "2022-06-27T10:07:04Z")

</div>

> [@Nacho\_Caballero](#):
>
> Is there a way to bypass the iframe-to-URL conversion altogether? Just like we already do with polls, it says something like “Click here to see the poll”

Thanks, Sam. Can you think of any temporary workarounds to prevent people from seeing the URL on email without having to hide it in a `[details]` tag?

---

<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: [June 28, 2022, 6:20am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/4 "2022-06-28T06:20:26Z")

</div>

Honestly, I can not think of many workarounds here short of maybe forcing a non oneboxed link underneath it?

```plaintext
https://vimeo.com/185876954
<https://vimeo.com/185876954>

```

[https://vimeo.com/185876954](https://vimeo.com/185876954)  
[https://vimeo.com/185876954](https://vimeo.com/185876954)

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [June 29, 2022, 11:38am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/5 "2022-06-29T11:38:59Z")

</div>

@Nacho_Caballero The example you provided of an video that is unlisted, unlisted videos have different url structure.

And the way to embed unlisted video as per Vimeo request is different, ref [Use oEmbed with private videos – Vimeo Help Center](https://vimeo.zendesk.com/hc/en-us/articles/360042542372-Use-oEmbed-with-private-videos)

I think a way around may be is to created your own embed using the doc above.

@sam  
And for discourse, would it be better may be to use viemo API to get embed src url instaed of building it. ref [https://stackoverflow.com/questions/51414260/vimeo-url-ive-never-seen-before-with-two-different-ids-how-do-i-get-it-to-work](https://stackoverflow.com/questions/51414260/vimeo-url-ive-never-seen-before-with-two-different-ids-how-do-i-get-it-to-work) . And those lines releavnt [discourse/lib/onebox/engine/vimeo\_onebox.rb at 657256a099a601a0694d11d15c42ad76988efe8c · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/657256a099a601a0694d11d15c42ad76988efe8c/lib/onebox/engine/vimeo_onebox.rb#L20-L35)

Anyway if my specualtion is right then this should affect typical posting not only email: [1-Minute Audio Test for Stereo Speakers &amp; Headphones-2ZrWHtvSog4](https://vimeo.com/508864124/fcbbcc92fa)

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [June 29, 2022, 11:47am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/6 "2022-06-29T11:47:49Z")

</div>

To get the iframe I did:

`GET` `https://vimeo.com/api/oembed.json?url=https://vimeo.com/508864124/fcbbcc92fa`  
So I got

```json
{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"https:\/\/vimeo.com\/","html":"<iframe src=\"https:\/\/player.vimeo.com\/video\/508864124?h=fcbbcc92fa&amp;app_id=122963\" width=\"426\" height=\"240\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture\" allowfullscreen><\/iframe>","width":426,"height":240,"domain_status_code":403,"video_id":508864124,"uri":"\/videos\/508864124:fcbbcc92fa"}

```

UTF-8 Decoded: for the iframe

```plaintext
<iframe src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa&amp;app_id=122963" width="426" height="240" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>

```

The iframe itself

https://player.vimeo.com/video/508864124?h=fcbbcc92fa&app_id=122963

Edit/Update:

I have submitted a PR to fix, I think the problem was with regex pattern. It didn’t captured vimeo correcly when its not the standard type. Thus I changed the regex pattern accordingly.  
[https://github.com/discourse/discourse/pull/17277](https://github.com/discourse/discourse/pull/17277)

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [October 31, 2022, 7:23am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/7 "2022-10-31T07:23:28Z")

</div>

@ghassan I just noticed this is still an issue.

If an iframe has an unlisted video, the URL isn’t transformed correctly in the email. For example:

```plaintext
<iframe src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>

```

Gets transformed into this (which is a 404): `https://vimeo.com/508864124?h=fcbbcc92fa`  
Instead of the correct URL: `https://vimeo.com/508864124/fcbbcc92fa`

Maybe the regex that you added in your PR needs an extra step (transform `?h=` into `/` when sending an email)

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [November 1, 2022, 8:49am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/8 "2022-11-01T08:49:48Z")

</div>

I am trying to remember/resummarize this:

So just to get this straight,

- There are different types of format of viemo urls, our only issue is with email side of thing, right?
- To replicate this, one needs to do what:
  - Paste url or iframe on topic (What are all cases of this)
  - It should work as expected on the web but if an email sent with the content of the topic then we it get tricky

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [November 1, 2022, 9:52am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/9 "2022-11-01T09:52:35Z")

</div>

> [@ghassan](#):
>
> There are different types of format of viemo urls, our only issue is with email side of thing, right?

Yes. The regex change you did made it possible to recognize iframe src URLs (`https://player.vimeo.com/video/508864124?h=fcbbcc92fa`), so that’s no longer a problem. The issue is on the email that gets sent.

> [@ghassan](#):
>
> Paste url or iframe on topic (What are all cases of this)

If you paste a plain url (`https://vimeo.com/508864124/fcbbcc92fa`), there’s no issue. It’s only a problem with the iframe src (`https://player.vimeo.com/video/508864124?h=fcbbcc92fa`).

> [@ghassan](#):
>
> It should work as expected on the web

It currently does.

> [@ghassan](#):
>
> if an email sent with the content of the topic then we it get tricky

Yes. Currently, the iframe src (`https://player.vimeo.com/video/508864124?h=fcbbcc92fa`) gets converted to this: `https://vimeo.com/508864124?h=fcbbcc92fa` instead of this: `https://vimeo.com/508864124/fcbbcc92fa`

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [November 6, 2022, 9:32am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/10 "2022-11-06T09:32:04Z")

</div>

It’s still hard for me to reproduce because I need to have a premium account to have unlisted video on vimeo.

Also I think your example of video above allow only to loaded from certiain domain, can you allow my sandbox instance to load it as well: `https://discuss.gsgapp.io`.

Again and be crystal clear, you don’t expect the video to play on E-mail, but you expect when people click on video position to be directed to the correct url? Am I right with that?

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [November 6, 2022, 11:14am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/11 "2022-11-06T11:14:50Z")

</div>

> [@ghassan](#):
>
> can you allow my sandbox instance to load it as well: `https://discuss.gsgapp.io`.

Done 👍

> [@ghassan](#):
>
> you don’t expect the video to play on E-mail, but you expect when people click on video position to be directed to the correct url?

Correct 👍

Thanks for the help!

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [November 6, 2022, 11:57am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/12 "2022-11-06T11:57:47Z")

</div>

Aha found the issue now:

So what is happening is that when you paste vanila iframe code, then you might bypass onebox code, and if you pass it then the result iframe code will not have `data-original-href` which is the link that is used in email template.

And when `data-original-href` is missing discourse tries to guess to the video is that is whatever is after the last `/` which is of course doesn’t cover the case of unlisted video.

> <https://github.com/discourse/discourse/blob/dea44ec923b1f4fced6dafbbf8109820cf1ca7a4/lib/pretty_text.rb#L479-L490>

For example if you check the dev tools/inspect element from your browser, the result iframe when using vanfila iframe code:

`<iframe src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen ></iframe>`

```html
<iframe src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen=""></iframe>

```

While when pasting just url, i.e. let discourse convert it to iframe  
`https://vimeo.com/508864124/fcbbcc92fa`.

```html
<iframe class="vimeo-onebox" src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa&amp;app_id=122963" data-original-href="https://vimeo.com/508864124/fcbbcc92fa" frameborder="0" allowfullscreen="" seamless="seamless" sandbox="allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-presentation"></iframe>

```

So notice the extra `data-original-href="https://vimeo.com/508864124/fcbbcc92fa"` in the second output, one might guess if that attribute when using iframe vanilla then it should work, but it doesn’t probably because discourse doesn’t allow you to add any attriubte you want…

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [November 6, 2022, 12:11pm UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/13 "2022-11-06T12:11:40Z")

</div>

I think I can suggest a solution, and while ensuring it would work for the case when the video is listed/public I came with this ucommon beahvour of vimeo. So typically all videos that are public folllow this pattern `vimeo.com/{id}` however it will work if you add a slash i.e. `vimeo.com/{id}/anything`

Consider the following example:

- `https://vimeo.com/767548129/estgsetgset`
- `https://vimeo.com/767548129/hey-discurse`
- `https://vimeo.com/767548129` _The normal_

All the above lead to the same video, so the fix can be that to create a url from iframe src, `vimeo.com/{_what comes after the first slash}/{What comes from the h=}` This shall make it work for both cases.

---

<div class="post-metadata">

### Author: ![ghassan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghassan/32/263566_2.png) [@ghassan](https://meta.discourse.org/u/ghassan)
#### Post date: [November 6, 2022, 12:47pm UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/14 "2022-11-06T12:47:01Z")

</div>

The proposed fix [FIX: vimeo iframe url when data-original-href is missing by ghassanmas · Pull Request #18894 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/18894) , you can also try it at [https://discuss.gsgapp.io](https://discuss.gsgapp.io) where I cherry-picked my commit.

I have perosnally tested for 4 cases:

- pasting vimeo url of public video
- pasting vimeo url of unlisted video
- pasting iframe vanila of of public video
- pasting iframe vanila of unlisted video

In all cases it lead to the email generating the correct url.

But anyway please try to test for all other possible variation that you might encournter and most importantly that it doesn’t break other thing.

The way I tested the e-mail template is that I would send myself a direct message, and then check the email inbox. (_Since I have two accounts regitered at [https://discuss.gsgapp.io](https://discuss.gsgapp.io)_)

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [November 7, 2022, 10:25am UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/15 "2022-11-07T10:25:40Z")

</div>

Thank you! I tested it as well and it works 👍

---

<div class="post-metadata">

### Author: ![Nacho\_Caballero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nacho_caballero/32/130189_2.png) [@Nacho\_Caballero](https://meta.discourse.org/u/Nacho_Caballero)
#### Post date: [April 19, 2023, 12:16pm UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/16 "2023-04-19T12:16:25Z")

</div>

testing:

[![](https://global.discourse-cdn.com/meta/original/4X/4/c/8/4c8bc3825f0d6c3121d22ac3c7a8066cb511efc5.jpeg "1-Minute Audio Test for Stereo Speakers & Headphones-2ZrWHtvSog4") ](https://vimeo.com/508864124/fcbbcc92fa)

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [June 28, 2024, 7:46pm UTC](https://meta.discourse.org/t/vimeo-embed-urls-parsed-incorrectly-in-email/231042/18 "2024-06-28T19:46:43Z")

</div>

It’s been merged
