Extension, Plugin

Developer
Supported

EE 1
EE 2
Minimee

Back to this add-on's main page
View Other Add-ons From John D. Wells

     

You must be logged in to post.

Base64 Encoding & Incorrectly Rewriting Background Image URLs

Bug Report

Trevor Davis
Trevor Davis

EE 2.2 Build 20110622
Minimee 1.1.3

This is kind of a bug report and a feature request in one.

We were base64 encoding some images, and I think the code that rewrites the background image urls was breaking in some instances. The one image (which was ridiculously long so I won’t paste it in here) was working fine and the URL didn’t get rewritten at all.

But the second image:

.hiring .button {
  background
-imageurl(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAACCAYAAAB7Xa1eAAAAFUlEQVQIHWNyqFJYhg0zyZlxMmDDAGyjCzNMrO7nAAAAAElFTkSuQmCC);

Was being rewritten as:

url(http://sitename.com//stylesheets/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAACCAYAAAB7Xa1eAAAAFUlEQVQIHWNyqFJYhg0zyZlxMmDDAGyjCzNMrO7nAAAAAElFTkSuQmCC); 

I went into libraries/cssmin.php and commented out lines 370-392 (the bit that does the URL rewriting) and that solved the problem.

So I guess the feature request would be a way to turn off the URL rewriting. Let me know if I can provide any more details.

John D Wells
# 1
Developer
John D Wells

Hi Trevor,

Hmm… OK, I might be able to work this out.  Since you seem to not mind getting your hands dirty with code, would you mind trying something?

1. First of all, restore cssmin.php to it’s original code.
2. Open up pi.minimee.php, go to line 847, and remove the second parameter passed to $this->_minify().
3. Then go to line 954, and again remove the second parameter passed to $this->_minify().

Then manually clear your Minimee cache (or update any of your CSS files), and see what happens.  That should skip the URL prepending altogether, and hopefully leave your image intact.

If that works for you, I’ll plan on supporting a configuration flag in a future release.  When I get around to it (could be a while!) I might bother you to test it again. :)

Cheers,
John

Trevor Davis
# 2
Trevor Davis

Yep, that seems to work perfectly. Thanks! Feel free to get in touch if you want me to test the next version.

Fusionary
# 3
Fusionary

I had this same problem, and this fix worked.

What is the reason for prepending the absolute url anyway?

Fusionary
# 4
Fusionary

Oh duh, cause they’re not relative to your css dir anymore.

Well, that fixed my base64 encoded stuff, but also broke all my other images.

Eli Van Zoeren
# 5
Eli Van Zoeren

This fix worked for me as well, although the line numbers are now 811 and 918. Obviously, as noted above, it only works if your other image paths in CSS are already root-relative. Would be great someday to have a more “official” fix… perhaps something as simple as a check in the Minify code for the string “data:image” at the beginning of a URL.

John D Wells
# 6
Developer
John D Wells

Hi Eli,

In the upcoming release of Minimee 2, this issue will be ‘officially’ dealt with - the newest versions of the Minify’s UriRewriter class does exactly as you suggests, looking for the data protocol and skipping if found.

If you’re willing to test, the beta of Minimee 2 is available on my Github account, any feedback is greatly appreciated:

https://github.com/johndwells/Minimee/tree/version2

Cheers,
John

Eli Van Zoeren
# 7
Eli Van Zoeren

Wow! So much good new stuff in v2! I will install it this afternoon and start playing around. I see you’ve already fixed my other outstanding issue, root-relative urls for https support. Thanks!

a&m impact
# 8
a&m impact

Although I know now it’s been fixed in the newest release I would like to share I had the same problem. Very glad to see it’s been fixed! Good support on a free add-on, thanks!