Prevent resource hint registration for pattern with leading slash
Prior to this commit, if a ResourcePatternHint was created with a resource pattern with a leading slash, the hint was registered and eventually converted to configuration for the GraalVM native image compiler. However, such a resource pattern is invalid for GraalVM. Consequently, the registered resources were not available within the compiled native image. This commit ensures that registered patterns are applicable in a native image by preventing creation of a ResourcePatternHint with a pattern with a leading slash. Closes gh-29088
This commit is contained in:
@@ -19,13 +19,22 @@ package org.springframework.aot.hint;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResourcePatternHint}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class ResourcePatternHintTests {
|
||||
class ResourcePatternHintTests {
|
||||
|
||||
@Test
|
||||
void patternWithLeadingSlashIsRejected() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ResourcePatternHint("/file.properties", null))
|
||||
.withMessage("Resource pattern [/file.properties] must not start with a '/'");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileAtRoot() {
|
||||
@@ -66,4 +75,5 @@ public class ResourcePatternHintTests {
|
||||
.accepts("com/example/file.properties", "com/example/another/file.properties", "com/example/another")
|
||||
.rejects("file.properties", "com/file.properties");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user