Fix: trim prefix slash in ListObjectVersionsHandler (#7919)

* Fix: trim prefix slash in ListObjectVersionsHandler

* Add test for ListObjectVersions prefix handling

Test validates that prefix normalization works correctly with and without
leading slashes, ensuring the fix for /Veeam/Archive/ style prefixes.

* Simplify prefix test to validate normalization logic

The test now validates that the prefix normalization (TrimPrefix) works
correctly and that normalized prefixes match paths as expected. This is
a focused unit test that validates the core fix without requiring complex
mocking of the filer client.

* Enhance prefix test with full matchesPrefixFilter logic

Added test cases for directory traversal including:
- Directory matching with trailing slash
- canDescend logic for recursive directory search
- Full simulation of matchesPrefixFilter behavior

This provides more comprehensive coverage of the prefix normalization
fix and ensures it works correctly for both files and directories.
This commit is contained in:
Chris Lu
2025-12-30 14:54:37 -08:00
committed by GitHub
parent 73098c9792
commit b034cf188e
2 changed files with 85 additions and 1 deletions

View File

@@ -985,7 +985,7 @@ func (s3a *S3ApiServer) ListObjectVersionsHandler(w http.ResponseWriter, r *http
// Parse query parameters
query := r.URL.Query()
originalPrefix := query.Get("prefix") // Keep original prefix for response
prefix := originalPrefix // Use for internal processing
prefix := strings.TrimPrefix(originalPrefix, "/")
// Note: prefix is used for filtering relative to bucket root, so no leading slash needed
keyMarker := query.Get("key-marker")