# JavaScript embedding doesn't add directory slash importing image paths, breaks images

**URL:** https://meta.discourse.org/t/javascript-embedding-doesnt-add-directory-slash-importing-image-paths-breaks-images/83204
**Category:** Bug
**Tags:** embedding
**Created:** [March 17, 2018, 2:25pm UTC](https://meta.discourse.org/t/javascript-embedding-doesnt-add-directory-slash-importing-image-paths-breaks-images/83204 "2018-03-17T14:25:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![icaria36](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/icaria36/32/426431_2.png) [@icaria36](https://meta.discourse.org/u/icaria36)
#### Post date: [March 17, 2018, 2:25pm UTC](https://meta.discourse.org/t/javascript-embedding-doesnt-add-directory-slash-importing-image-paths-breaks-images/83204/1 "2018-03-17T14:25:55Z")

</div>

This looks like… a simple bug?

- Example source page: [http://surtdelcercle.cat/index.php?view=blog&id=6](http://surtdelcercle.cat/index.php?view=blog&id=6)

- Images are called with relative paths: `src="media/torbrowser.jpg"`

- Resulting URL: [http://surtdelcercle.cat/media/torbrowser.jpg](http://surtdelcercle.cat/media/torbrowser.jpg) (correct)

- Imported page: [Redirecting...](https://la.confederac.io/t/surt-del-cercle/2865) (notice the broken images)

- The imported image URL: [http://surtdelcercle.catmedia/torbrowser.jpg](http://surtdelcercle.catmedia/torbrowser.jpg) (broken)

Note the slash missing in “catmedia”.

I didn’t find a report for this bug, although this one might be related: [https://meta.discourse.org/t/embedded-topics-dont-handle-images-properly/37355](https://meta.discourse.org/t/embedded-topics-dont-handle-images-properly/37355)

Can anyone reproduce? Or is there a fix that we could implement on our side? (other than defining images with absolute URLs, which we could do moving forward but what about the articles already published)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 31, 2020, 8:49pm UTC](https://meta.discourse.org/t/javascript-embedding-doesnt-add-directory-slash-importing-image-paths-breaks-images/83204/2 "2020-07-31T20:49:49Z")

</div>

> [@icaria36](#):
>
> Can anyone reproduce?

Well, it’s been a while, but yes.

> <https://github.com/discourse/discourse/blob/0b3f9638047a37bf6626bf2d6aa74299be5cd55e/app/models/topic_embed.rb#L217-L224>

The above code appears to normalize image URLs that start with a `/` (fixing up the hostname), but not those relative to the current URL.

Maybe that should instead be this?

```ruby
    if src.present? && !src.start_with?('http')

```

If I’m right, I think that the code a few lines above has the same bug.
