HttpStapler change url for external/absolute and data resources
KarolBedkowski opened this issue · comments
Current behavior
Jodd 4.x and 5.0.10.
Stapler change absolute urls in css, i.e.:
@import url('https://fonts.googleapis.com/css?family=Roboto:300,400,500,700');/*!
background-image:url(data:image/png;base64,iVBORw0KGgoAAAAN....
to ('/s/css' is my locations for css)
@import url('../s/css/https://fonts.googleapis.com/css?family=Roboto:300,400,500,700');/*!
background-image:url('../s/css/data:image/png;base64,iVBORw0KGgoAAAAN...
so this resources can't be found.
Expected behavior
Stapler should not change urls for resources prefixed with data or http.
Steps to Reproduce the Problem
Create css with content like above.
Temporary solution
Extend HtmlStaplerBundlesManager like below work for me, but there may be better solution...
public class MyHtmlStaplerBundlesManager extends HtmlStaplerBundlesManager {
public MyHtmlStaplerBundlesManager(final String contextPath,
final String webRoot, final Strategy strategy) {
super(contextPath, webRoot, strategy);
}
@Override
protected String fixRelativeUrl(final String url, final String offsetPath) {
if (url.startsWith("data") || url.startsWith("\"http")) {
return new StringBuilder()
.append("url(")
.append(url)
.append(')')
.toString();
}
return super.fixRelativeUrl(url, offsetPath);
}
}
Good catch! Thank you, HTML stapler is not used that much in the wild, but I find it very useful.
The fix is very similar to what you have, just checked before calling this method.
Btw if you need any support or help with Jodd, let me know; also and feedback is appreciated :)
Thank you.
I'm using Jodd for years without any problems - it is great framework.
If I may suggest - some kind of sample project that show new users how to glue all components in real / advanced application (with joy, vtor (and custom validators), petite, maybe external quartz/hikari, etc.) will be helpful. Now some time is required to understand what's going on and how to setup in sane way.
@KarolBedkowski got it... for that purpose I made http://joddframework.org, but it is not updated. I will try to do that!