Skip to content

Commit

Permalink
WICKET-7024 skip cache update if resource is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrosans committed Nov 4, 2024
1 parent 47e1d23 commit 6534d8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,25 @@ public void decodeStyleFromUrl()
assertThat(tester.getLastResponseAsString(), not(containsString("blue")));
}

@Test
public void doNotFindNullResourceInTheCache()
{
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
when(resourceStreamLocator.locate(scope, "org/apache/wicket/core/request/resource/z.css",
"orange", null, null, null, false)).thenReturn(null);

tester.getApplication().getResourceSettings()
.setResourceStreamLocator(new CachingResourceStreamLocator(resourceStreamLocator));

tester.executeUrl(
"wicket/resource/org.apache.wicket.core.request.resource.PackageResourceReferenceTest/z.css?-orange");
tester.executeUrl(
"wicket/resource/org.apache.wicket.core.request.resource.PackageResourceReferenceTest/z.css?-orange");

verify(resourceStreamLocator, times(2)).locate(PackageResourceReferenceTest.class,
"org/apache/wicket/core/request/resource/z.css", "orange", null, null, null, false);
}

@Test
public void doNotFindResourceInTheCache()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,17 @@ public IRequestHandler mapRequest(Request request)

if (scope != null && scope.getPackage() != null)
{
attributes = PackageResource.sanitize(attributes, scope, name.toString());
ResourceReference.UrlAttributes sanitized = PackageResource.sanitize(attributes, scope, name.toString());
boolean createIfNotFound = false;
if (sanitized != null)
{
attributes = sanitized;
createIfNotFound = true;
}

ResourceReference res = getContext().getResourceReferenceRegistry()
.getResourceReference(scope, name.toString(), attributes.getLocale(),
attributes.getStyle(), attributes.getVariation(), true, true);
attributes.getStyle(), attributes.getVariation(), true, createIfNotFound);

if (res != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public PackageResource readBuffered(boolean readBuffered)

/**
* @return UrlAttributes with an existent locale/style/variation if a resource is bound to the
* scope+name
* scope+name, otherwise returns null
*/
public static ResourceReference.UrlAttributes sanitize(
ResourceReference.UrlAttributes urlAttributes, Class<?> scope, String name)
Expand All @@ -880,7 +880,7 @@ public static ResourceReference.UrlAttributes sanitize(
urlAttributes.getStyle(), urlAttributes.getVariation(), false);
if (filesystemMatch == null)
{
return urlAttributes;
return null;
}
try
{
Expand Down

0 comments on commit 6534d8d

Please sign in to comment.