Skip to content

Commit 4af5229

Browse files
committed
Verify that CssLinkResourceTransformer handles empty url() links
This commit introduces a test that verifies that CssLinkResourceTransformer properly handles empty url() functions in CSS files. See gh-22602
1 parent ae2ecf0 commit 4af5229

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -32,10 +32,10 @@
3232
import static org.junit.Assert.*;
3333

3434
/**
35-
* Unit tests for
36-
* {@link org.springframework.web.servlet.resource.CssLinkResourceTransformer}.
35+
* Unit tests for {@link CssLinkResourceTransformer}.
3736
*
3837
* @author Rossen Stoyanchev
38+
* @author Sam Brannen
3939
* @since 4.1
4040
*/
4141
public class CssLinkResourceTransformerTests {
@@ -120,4 +120,23 @@ public void transformWithNonCssResource() throws Exception {
120120
assertSame(expected, actual);
121121
}
122122

123+
@Test // https://github.com/spring-projects/spring-framework/issues/22602
124+
public void transformEmptyUrlFunction() throws Exception {
125+
this.request = new MockHttpServletRequest("GET", "/static/empty_url_function.css");
126+
Resource css = getResource("empty_url_function.css");
127+
String expected =
128+
".fooStyle {\n" +
129+
"\tbackground: transparent url() no-repeat left top;\n" +
130+
"}";
131+
132+
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css);
133+
String result = new String(actual.getByteArray(), "UTF-8");
134+
result = StringUtils.deleteAny(result, "\r");
135+
assertEquals(expected, result);
136+
}
137+
138+
private Resource getResource(String filePath) {
139+
return new ClassPathResource("test/" + filePath, getClass());
140+
}
141+
123142
}
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)