提交 9ada55dc 编写于 作者: B Brian Clozel

Fix NPE in GzipResourceResolver

This change fixes a NullPointerException in GzipResourceResolver, which
assumed that calls to the `resolveResource` method were made with only
non-null values for request.

This is not the case for the VersionResourceResolver, which tries to
resolve resources that aren't requested per se by the HTTP request.

Issue: SPR-13149
上级 3b6548f3
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -48,7 +48,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
List<? extends Resource> locations, ResourceResolverChain chain) {
Resource resource = chain.resolveResource(request, requestPath, locations);
if ((resource == null) || !isGzipAccepted(request)) {
if ((resource == null) || (request != null && !isGzipAccepted(request))) {
return resource;
}
......
......@@ -149,4 +149,21 @@ public class GzipResourceResolverTests {
assertFalse("Expected " + resolved + " to *not* be of type " + EncodedResource.class,
resolved instanceof EncodedResource);
}
// SPR-13149
@Test
public void resolveWithNullRequest() throws IOException {
String file = "js/foo.js";
String gzFile = file+".gz";
Resource gzResource = new ClassPathResource("test/"+gzFile, getClass());
// resolved resource is now cached in CachingResourceResolver
Resource resolved = resolver.resolveResource(null, file, locations);
assertEquals(gzResource.getDescription(), resolved.getDescription());
assertEquals(new ClassPathResource("test/" + file).getFilename(), resolved.getFilename());
assertTrue("Expected " + resolved + " to be of type " + EncodedResource.class,
resolved instanceof EncodedResource);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册