Skip to content

Commit 6534d8d

Browse files
committed
WICKET-7024 skip cache update if resource is not found
1 parent 47e1d23 commit 6534d8d

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

wicket-core-tests/src/test/java/org/apache/wicket/core/request/resource/PackageResourceReferenceTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,25 @@ public void decodeStyleFromUrl()
443443
assertThat(tester.getLastResponseAsString(), not(containsString("blue")));
444444
}
445445

446+
@Test
447+
public void doNotFindNullResourceInTheCache()
448+
{
449+
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
450+
when(resourceStreamLocator.locate(scope, "org/apache/wicket/core/request/resource/z.css",
451+
"orange", null, null, null, false)).thenReturn(null);
452+
453+
tester.getApplication().getResourceSettings()
454+
.setResourceStreamLocator(new CachingResourceStreamLocator(resourceStreamLocator));
455+
456+
tester.executeUrl(
457+
"wicket/resource/org.apache.wicket.core.request.resource.PackageResourceReferenceTest/z.css?-orange");
458+
tester.executeUrl(
459+
"wicket/resource/org.apache.wicket.core.request.resource.PackageResourceReferenceTest/z.css?-orange");
460+
461+
verify(resourceStreamLocator, times(2)).locate(PackageResourceReferenceTest.class,
462+
"org/apache/wicket/core/request/resource/z.css", "orange", null, null, null, false);
463+
}
464+
446465
@Test
447466
public void doNotFindResourceInTheCache()
448467
{

wicket-core/src/main/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapper.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,17 @@ public IRequestHandler mapRequest(Request request)
132132

133133
if (scope != null && scope.getPackage() != null)
134134
{
135-
attributes = PackageResource.sanitize(attributes, scope, name.toString());
135+
ResourceReference.UrlAttributes sanitized = PackageResource.sanitize(attributes, scope, name.toString());
136+
boolean createIfNotFound = false;
137+
if (sanitized != null)
138+
{
139+
attributes = sanitized;
140+
createIfNotFound = true;
141+
}
136142

137143
ResourceReference res = getContext().getResourceReferenceRegistry()
138144
.getResourceReference(scope, name.toString(), attributes.getLocale(),
139-
attributes.getStyle(), attributes.getVariation(), true, true);
145+
attributes.getStyle(), attributes.getVariation(), true, createIfNotFound);
140146

141147
if (res != null)
142148
{

wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ public PackageResource readBuffered(boolean readBuffered)
871871

872872
/**
873873
* @return UrlAttributes with an existent locale/style/variation if a resource is bound to the
874-
* scope+name
874+
* scope+name, otherwise returns null
875875
*/
876876
public static ResourceReference.UrlAttributes sanitize(
877877
ResourceReference.UrlAttributes urlAttributes, Class<?> scope, String name)
@@ -880,7 +880,7 @@ public static ResourceReference.UrlAttributes sanitize(
880880
urlAttributes.getStyle(), urlAttributes.getVariation(), false);
881881
if (filesystemMatch == null)
882882
{
883-
return urlAttributes;
883+
return null;
884884
}
885885
try
886886
{

0 commit comments

Comments
 (0)