Ignore external resources in CssLinkResourceTransormer
Prior to this commit, the CssLinkResourceTransformer would transform "external resources", i.e. resources not served by the web application. This commit only allows transformation for resources which path don't contain scheme such as "file://" or "http://". Only relative and absolute paths for resources served by the webapp are valid. Issue: SPR-11860
This commit is contained in:
@@ -101,7 +101,10 @@ public class CssLinkResourceTransformer implements ResourceTransformer {
|
||||
for (CssLinkInfo info : sortedInfos) {
|
||||
writer.write(content.substring(index, info.getStart()));
|
||||
String link = content.substring(info.getStart(), info.getEnd());
|
||||
String newLink = transformerChain.getResolverChain().resolveUrlPath(link, Arrays.asList(resource));
|
||||
String newLink = null;
|
||||
if(!hasScheme(link)) {
|
||||
newLink = transformerChain.getResolverChain().resolveUrlPath(link, Arrays.asList(resource));
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
if (newLink != null && !link.equals(newLink)) {
|
||||
logger.trace("Link modified: " + newLink + " (original: " + link + ")");
|
||||
@@ -118,6 +121,11 @@ public class CssLinkResourceTransformer implements ResourceTransformer {
|
||||
return new TransformedResource(resource, writer.toString().getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
|
||||
private boolean hasScheme(String link) {
|
||||
int schemeIndex = link.indexOf(":");
|
||||
return schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/");
|
||||
}
|
||||
|
||||
|
||||
protected static interface CssLinkParser {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user