Remote image download shouldn't touch code sections


(Patrick Klug) #1

I wanted to explain to a user how to use the [img] tags like so:

You can use the image tags to link directly to an image. Example:

[img]//discourse-meta.s3-us-west-1.amazonaws.com/original/3X/9/4/946ade3ba6e4421e845cb80b010ad94307ef6bd6.png[/img]

results in:

A few seconds later the system goes and grabs that image and changes the img link (good) and the code section (bad).

Code sections of the text should be ignored when adjusting links like that.


System user replaces wrong URL when it downloads local copy of image
(Patrick Klug) #2

I’m just waiting for the system to grab the remote image in the above post to finish my demonstration…

EDIT: meta.discourse doesn’t seem to grab remote images? is that correct @sam?


(Patrick Klug) #3

No idea why it took the system over 2 months to crawl that image but now the issue is reproduced:

Image url’s inside a code block should not be crawled and the system should not adjust the text.


(Kane York) #4

I believe the workaround was to use an image URL that you don’t also use elsewhere in the post, right?

Test:

[img]http://www.greenheartgames.com/wp-content/uploads/2013/12/ghg_small.png[/img]

EDIT: Yep, confirmed in code - it will only run if there is an <img> in the cooked output, and for the source attributes of those <img>s only.


(Patrick Klug) #5

testing:

[img]http://www.greenheartgames.com/wp-content/uploads/2013/12/ghg_small.png[/img]

EDIT: confirmed


(Sam Saffron) #6

This is a bug here:

Unfortunately fixing this is a royal nightmare multiplied by 10.

There are 3 approaches we could take:

  1. Stop touching raw, and instead have a mapping layer for hotlinked images, apply it in cooked. This could lead to confusing behavior.

  2. Leverage the markdown parser and only muck around with “real” images in the markdown, rebuild markdown once replacement is done.

  3. Introduce a tower of regex hacks

None of these approaches are particularly appealing to me, I am tending to just live with this bug for now cause it is such an edge case.

cc @zogstrip @eviltrout


(Jeff Atwood) #7

Agree, special case, we will just live with it now that we know the specific conditions it occurs under.


(Jeff Atwood) #8