This project is read-only.
53
Vote

CssRewriteUrlTransform doesn't ignore embedded data URIs

description

@font-face {
  font-family: "Proxima Nova";
  src: url("data:font/opentype;base64,d09GRgABAAAAAE/kABIasdfbasdfasdfETCETERA")
  font-style: normal;
  font-weight: normal;
}
This problem occurs with the quotations url("data:...") or without the quotations url(data:....)
The result in both cases is the following when rewritten:
@font-face{font-family:"Proxima Nova";src:url(/themes/base/css/data:font/opentype;base64,d09GRgA.......);...}
where themes/base/css is the rewritten path it thinks needs to be there but shouldn't be

Cheers,
Ben

comments

benmccallum wrote May 20, 2013 at 6:30 AM

Fix is to also check for
url.StartsWith("data:") 
in the RebaseUrlToAbsolute method of CssRewriteTransform so that if true, the existing value of "url" is returned and the baseUrl is not appended.

suhasj wrote Jun 5, 2013 at 9:24 PM

Related work item https://aspnetoptimization.codeplex.com/workitem/86. Was able to reproduce the issue and looks like a possible bug.

literadesign wrote Mar 7, 2014 at 1:38 PM

Fix is to also check for
url.StartsWith("http");
because this would also solve problems with imported external fonts (i.e. Google Fonts) that use this notation:
@import url(http://fonts.googleapis.com/css?family=Open+Sans);

benmccallum wrote Mar 7, 2014 at 11:58 PM

Good pickup @literadesign !

hwiechers wrote Mar 22, 2014 at 9:52 AM

This issue one is almost a year old and currently the top voted.
I hope it gets fixed soon.

benmccallum wrote Mar 22, 2014 at 10:09 AM

What I did was just decompile the class I mentioned in my comment, put it in a new file in your project, with the same namespace as Microsoft's assembly, change the class name slightly, and implemented the fixes mentioned above. Then refer to that fixed class as your Transformer. Workaround for now.

benmccallum wrote Mar 24, 2014 at 2:10 AM

Hi all,

I've uploaded some source code for bundling and the like that I use into GitHub here:
https://github.com/benmccallum/AspNetBundling

Includes the fix for the Css Rewrite Url Tranformer as I hinted at earlier.

Hope this helps people.

Cheers,
Ben

miksh wrote Aug 7, 2014 at 8:49 PM

I want to repeat comment made in March 2014

_This issue one is almost a year old and currently the top voted.
I hope it gets fixed soon._

Now it is August... still waiting...

benmccallum wrote Oct 3, 2014 at 9:41 AM

FYI my solution to this is now a NuGet package.

Repo is @ https://github.com/benmccallum/AspNetBundling

NuGet Gallery page is @ https://www.nuget.org/packages/AspNetBundling

Or just:
Install-Package AspNetBundling

fabrice wrote Oct 17, 2014 at 11:20 AM

Thank you benmccalum!

fabrice wrote Oct 21, 2014 at 4:34 PM

Unfortunately, your solution does not work as is, benmccallum.
CssRewriteUrlTransformFixed does not include a fix that CssRewriteUrlTransform (System.Web.Optimization, Version=1.1.0.0) has: it breaks relative url references in CSS files.

Could you please fix this? In the meantime, I have to rollback to CssRewriteUrlTransform.

Will Microsoft fix the current bug one day in System.Web.Optimization?

fabrice wrote Oct 21, 2014 at 10:55 PM

It seems that in fact the problem comes from Microsoft.AspNet.Web.Optimization.
CssRewriteUrlTransform works fine in Microsoft.AspNet.Web.Optimization.1.1.0, but not Microsoft.AspNet.Web.Optimization.1.1.3.

I don't know what has changed.
I was fed up with all these issues. I ended up renaming my bundles (http://stackoverflow.com/a/24189608/56286).

benmccallum wrote Oct 31, 2014 at 2:24 PM

Are you sure it is an issue with my library fabrice? Happy to take a pull request if you care to compare the 1.1.0 and 1.1.3 versions of Microsoft.AspNet.Web.Optimization and see what is different and requires a change from me.

phoenix20_06 wrote Dec 3, 2014 at 7:13 PM

Any plans on implementing a fix for this issue?

khorvat wrote Mar 13, 2015 at 1:00 PM

Any news on the fix ?

benmccallum wrote Jul 27, 2015 at 3:22 PM

For anyone using my NuGet package, I've released another update to fix a scenario where a data URI is used for an SVG, but the format isn't base64 encoded.

Issue was logged here if anyone is interested and is now fixed in v2.0.2:
https://github.com/benmccallum/AspNetBundling/issues/8

Cheers.