fix(PathPatternResolver): remove leading slash from resolved pattern if first component is empty (#2339)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
+16
@@ -889,4 +889,20 @@ class PathPatternResolverTest {
|
||||
assertTrue(result.getBytes(StandardCharsets.UTF_8).length <= MAX_FILENAME_BYTES,
|
||||
"Result bytes should be <= " + MAX_FILENAME_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should remove leading slash from resolved pattern if first component is empty")
|
||||
void testResolvePattern_removesLeadingSlash_whenFirstComponentIsEmpty() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of()) // Empty authors
|
||||
.build();
|
||||
|
||||
// Pattern implies a subdirectory, but authors is missing
|
||||
// This resolves to "/Book Title.pdf" currently
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}/{title}", "original.pdf");
|
||||
|
||||
// This assertion ensures the path is relative (does not start with /)
|
||||
assertFalse(result.startsWith("/"), "Result should not start with slash: " + result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user