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:
Balázs Szücs
2026-01-19 08:50:45 -07:00
committed by GitHub
parent 87cefbffbc
commit da83a70281
2 changed files with 23 additions and 1 deletions
@@ -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);
}
}