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

This looks like… a simple bug?

Note the slash missing in “catmedia”.

I didn’t find a report for this bug, although this one might be related: Embedded topics don't handle "//"-images properly

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)

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?

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

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

2 Likes