Skip to content

Commit 95eb24d

Browse files
committed
Verify that CssLinkResourceTransformer handles empty url() links
This commit introduces tests that verify that both CssLinkResourceTransformer implementations properly handle empty url() functions in CSS files. See gh-22602
1 parent 699d75e commit 95eb24d

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/resource/CssLinkResourceTransformerTests.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,9 @@
3737

3838
/**
3939
* Unit tests for {@link CssLinkResourceTransformer}.
40+
*
4041
* @author Rossen Stoyanchev
42+
* @author Sam Brannen
4143
*/
4244
public class CssLinkResourceTransformerTests {
4345

@@ -159,6 +161,26 @@ public void transformSkippedForGzippedResource() throws Exception {
159161
.verify();
160162
}
161163

164+
@Test // https://github.com/spring-projects/spring-framework/issues/22602
165+
public void transformEmptyUrlFunction() throws Exception {
166+
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/empty_url_function.css"));
167+
Resource css = getResource("empty_url_function.css");
168+
String expected =
169+
".fooStyle {\n" +
170+
"\tbackground: transparent url() no-repeat left top;\n" +
171+
"}";
172+
173+
StepVerifier.create(this.transformerChain.transform(exchange, css)
174+
.cast(TransformedResource.class))
175+
.consumeNextWith(transformedResource -> {
176+
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
177+
result = StringUtils.deleteAny(result, "\r");
178+
assertEquals(expected, result);
179+
})
180+
.expectComplete()
181+
.verify();
182+
}
183+
162184
private Resource getResource(String filePath) {
163185
return new ClassPathResource("test/" + filePath, getClass());
164186
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.fooStyle {
2+
background: transparent url() no-repeat left top;
3+
}

spring-webmvc/src/test/java/org/springframework/web/servlet/resource/CssLinkResourceTransformerTests.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,11 +34,11 @@
3434
import static org.junit.Assert.*;
3535

3636
/**
37-
* Unit tests for
38-
* {@link org.springframework.web.servlet.resource.CssLinkResourceTransformer}.
37+
* Unit tests for {@link CssLinkResourceTransformer}.
3938
*
4039
* @author Rossen Stoyanchev
4140
* @author Brian Clozel
41+
* @author Sam Brannen
4242
* @since 4.1
4343
*/
4444
public class CssLinkResourceTransformerTests {
@@ -149,6 +149,21 @@ public void transformSkippedForGzippedResource() throws Exception {
149149
assertSame(gzipped, actual);
150150
}
151151

152+
@Test // https://github.com/spring-projects/spring-framework/issues/22602
153+
public void transformEmptyUrlFunction() throws Exception {
154+
this.request = new MockHttpServletRequest("GET", "/static/empty_url_function.css");
155+
Resource css = getResource("empty_url_function.css");
156+
String expected =
157+
".fooStyle {\n" +
158+
"\tbackground: transparent url() no-repeat left top;\n" +
159+
"}";
160+
161+
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css);
162+
String result = new String(actual.getByteArray(), StandardCharsets.UTF_8);
163+
result = StringUtils.deleteAny(result, "\r");
164+
assertEquals(expected, result);
165+
}
166+
152167
private Resource getResource(String filePath) {
153168
return new ClassPathResource("test/" + filePath, getClass());
154169
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.fooStyle {
2+
background: transparent url() no-repeat left top;
3+
}

0 commit comments

Comments
 (0)