-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(webmvc): fixes the trailing slash handling during resource locati…
…on resolution. closes gh-33815
- Loading branch information
1 parent
1255bd1
commit dc3ea16
Showing
3 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...mvc/src/test/java/org/springframework/web/servlet/resource/ResourceHandlerUtilsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.springframework.web.servlet.resource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests for {@link ResourceHandlerUtils}. | ||
* | ||
* @author Edoardo Patti | ||
*/ | ||
public class ResourceHandlerUtilsTests { | ||
|
||
@Test | ||
void testTrailingSlash() { | ||
var windowsDirectory = "META-INF\\resources\\webjars"; | ||
var directory = "META-INF/resources/webjars"; | ||
var directoryWithoutSlash = "META-INF"; | ||
var correctWindowsDirectory = "META-INF\\resources\\webjars\\"; | ||
var correctDirectory = "META-INF/resources/webjars/"; | ||
assertThat(ResourceHandlerUtils.addTrailingSlashIfAbsent(windowsDirectory).endsWith("\\")).isTrue(); | ||
assertThat(ResourceHandlerUtils.addTrailingSlashIfAbsent(directory).endsWith("/")).isTrue(); | ||
assertThat(ResourceHandlerUtils.addTrailingSlashIfAbsent(directoryWithoutSlash).endsWith("/")).isTrue(); | ||
assertThat(ResourceHandlerUtils.addTrailingSlashIfAbsent(correctWindowsDirectory)).isEqualTo(correctWindowsDirectory); | ||
assertThat(ResourceHandlerUtils.addTrailingSlashIfAbsent(correctDirectory)).isEqualTo(correctDirectory); | ||
} | ||
} |