Skip to content

Commit

Permalink
Adds SassResourceUrlSanitizer to recognize variants in the URL (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrosans authored Dec 31, 2024
1 parent fb709cd commit 05ffe8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.wicket.markup.html.IPackageResourceGuard;
import org.apache.wicket.markup.html.SecurePackageResourceGuard;
import org.apache.wicket.request.resource.IResourceReferenceFactory;
import org.apache.wicket.request.resource.IResourceUrlSanitizer;
import org.apache.wicket.request.resource.ResourceReferenceRegistry;

/**
Expand Down Expand Up @@ -39,6 +40,10 @@ public static void install(final Application app, final SassCompilerOptionsFacto
ResourceReferenceRegistry resourceReferenceRegistry = app.getResourceReferenceRegistry();
IResourceReferenceFactory delegate = resourceReferenceRegistry.getResourceReferenceFactory();
resourceReferenceRegistry.setResourceReferenceFactory(new SassResourceReferenceFactory(delegate));

IResourceUrlSanitizer sanitizer = app.getResourceSettings().getUrlSanitizer();
SassResourceUrlSanitizer sassSanitizer = new SassResourceUrlSanitizer(sanitizer);
app.getResourceSettings().setUrlSanitizer(sassSanitizer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.agilecoders.wicket.sass;

import org.apache.wicket.request.resource.IResourceUrlSanitizer;
import org.apache.wicket.request.resource.ResourceReference;

public class SassResourceUrlSanitizer implements IResourceUrlSanitizer
{

private IResourceUrlSanitizer delegate;

public SassResourceUrlSanitizer(IResourceUrlSanitizer delegate)
{
this.delegate = delegate;
}

@Override
public ResourceReference.UrlAttributes sanitize(ResourceReference.UrlAttributes urlAttributes,
Class<?> scope, String name)
{
if (ContextRelativeSassResourceReference.CONTEXT_RELATIVE_SASS_REFERENCE_VARIATION.equals(
urlAttributes.getVariation()))
{
return urlAttributes;
}
else
{
return delegate.sanitize(urlAttributes, scope, name);
}
}
}

0 comments on commit 05ffe8a

Please sign in to comment.