Better recognition for image URLs


(Alexandre Angelim) #1

Most of Rails applications append a query string on image URLs to manage versioning. I don’t know if this is common practice for other frameworks, but I’ve stumbled upon many sites using this approach.

When pasting(in the composer) an image url with a query string, discourse doesn’t seem to recognize it and leaves a link, instead. Can we parse the url taking that into account or is there another caveat I’m not considering?


(Jeff Atwood) #2

What you mean like this:

?foo=bar

Versus like this?

<img src='//discourse-meta.s3-us-west-1.amazonaws.com/original/2X/5/55a8020ac5d482a5f8c1aad218dcf8b42d6c4d0b.jpg'>

Most software on the Internet does expect image URLs to end in image filename extensions, so I don’t think this is a big deal.


(Kane York) #3

@codinghorror’s original post, before the system helpfully downloaded the images, editing his code block in the process:

What you mean like this:

https://www.google.com/logos/doodles/2014/percy-julians-115th-birthday-born-1899-5688801926053888-hp.jpg?foo=bar

Versus like this?

`https://www.google.com/logos/doodles/2014/percy-julians-115th-birthday-born-1899-5688801926053888-hp.jpg`
https://www.google.com/logos/doodles/2014/percy-julians-115th-birthday-born-1899-5688801926053888-hp.jpg

Most software on the Internet *does* expect image URLs to end in image filename extensions, so I don't think this is a big deal.

NB: The third link was oneboxed, the first was not.


(Alexandre Angelim) #4

Sorry. I should have given an example.
I mean like this:


(Sam Saffron) #5

Yeah, this would be a onebox bug, pull request? GitHub - discourse/onebox: A gem for turning URLs into website previews


(Jeff Atwood) #6

Could be a bug. Did it work that way (that is, ignore query strings) before? I can’t remember. Do you remember @eviltrout?


(Sam Saffron) #7

It’s a bug, don’t think it is a regression

EDIT

This may not be happening at the onebox level, not sure, need to read through the code


(Evaryont 🎆) #8

I think it is Onebox’s fault – it’s regex for the ImageEngine expects the URL to end with gif/jpg/png/etc, and doesn’t account for query parameters. I’ve got some code, but I’m working on some unit tests before I submit a pull request.

Edit: And now it’s done, opened a pull request.

https://github.com/discourse/onebox/pull/207

Edit #2: And once more, this time for audio/video URLs:

https://github.com/discourse/onebox/pull/205


(Robin Ward) #9

Thanks so much! I’ve pushed a new version of the gem and updated Discourse to depend on it. It’s available in master now and should be deployed to all our sites soonish.


(Jeff Atwood) #10