Fix image CID rewrite for some pasted images #1960

Merged
merged 1 commit into from Apr 29, 2015

Projects

None yet

3 participants

@greezybacon
Member

Copy+Pasting images from a ticket thread or from a FAQ article to the HTML editor and submitting will result in the URL not being properly rewritten for storage in the database. When images are uploaded, a relative URL is returned from the server and embedded in the HTML editor. However, when images from the system are copy and pasted into the editor, an absolute URL with the http:// scheme is included. This URL was not properly handled by the URL rewriter in Format::localizeInlineImages().

This patch addresses the issue by properly handling both relative URLs from image uploads and absolute URLs from copy and pasting.

Maybe fixes #334

@greezybacon greezybacon Fix image CID rewrite for some pasted images
Copy+Pasting images from a ticket thread or from a FAQ article to the HTML
editor and submitting will result in the URL *not* being properly rewritten
for storage in the database. When images are uploaded, a relative URL is
returned from the server and embedded in the HTML editor. However, when
images from the system are copy and pasted into the editor, an absolute URL
with the http:// scheme is included. This URL was not properly handled by
the URL rewriter in Format::localizeInlineImages().

This patch addresses the issue by properly handling both relative URLs from
image uploads and absolute URLs from copy and pasting.
cd538a8
@protich protich merged commit 2653238 into osTicket:develop Apr 29, 2015
@greezybacon greezybacon commented on the diff Apr 30, 2015
include/class.format.php
@@ -228,7 +228,7 @@ function safe_html($html) {
function localizeInlineImages($text) {
// Change file.php urls back to content-id's
return preg_replace(
- '/src="(?:\/[^"]+?)?\/file\\.php\\?(?:\w+=[^&]+&(?:amp;)?)*?key=([^&]+)[^"]*/',
+ '`src="(?:https?:/)?(?:/[^/"]+)*?/file\\.php\\?(?:\w+=[^&]+&(?:amp;)?)*?key=([^&]+)[^"]*`',
@greezybacon
greezybacon Apr 30, 2015 Member

I think the refer after key= should not match closing double quote, or else it might require a very significant backtrack to match

@arendtb
arendtb Nov 20, 2016 edited

I fixed this by using a workaround
I just clicked the HTML button and used the image source. I have the image on my word press site and just used img src="image url goes here"> worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment