oblac / jodd

Jodd! Lightweight. Java. Zero dependencies. Use what you like.
https://jodd.org
BSD 2-Clause "Simplified" License
4.06k stars 723 forks source link

HttpStapler change url for external/absolute and data resources #691

Closed KarolBedkowski closed 5 years ago

KarolBedkowski commented 5 years ago

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);
    }
}
igr commented 5 years ago

Good catch! Thank you, HTML stapler is not used that much in the wild, but I find it very useful.

igr commented 5 years ago

The fix is very similar to what you have, just checked before calling this method.

igr commented 5 years ago

Btw if you need any support or help with Jodd, let me know; also and feedback is appreciated :)

KarolBedkowski commented 5 years ago

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.

igr commented 5 years ago

@KarolBedkowski got it... for that purpose I made http://joddframework.org, but it is not updated. I will try to do that!