Skip to content

Commit

Permalink
fix(backup/gcs): accept '/' as base path and sanitize more reliably
Browse files Browse the repository at this point in the history
(cherry picked from commit b7a01b6)
  • Loading branch information
lenaschoenburg committed Apr 4, 2023
1 parent c3c75eb commit 8618e28
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ private static String requireBucketName(final String bucketName) {
}

private static String sanitizeBasePath(final String basePath) {
if (basePath == null || basePath.isBlank()) {
if (basePath == null) {
return null;
}

var sanitized = basePath.trim();
if (sanitized.isEmpty() || sanitized.equals("/")) {
return null;
}

// Remove one leading and one trailing slash if present.
String sanitized = basePath;
if (basePath.startsWith("/")) {
sanitized = basePath.substring(1);
while (sanitized.startsWith("/")) {
sanitized = sanitized.substring(1);
}
if (basePath.endsWith("/")) {
while (sanitized.endsWith("/")) {
sanitized = sanitized.substring(0, sanitized.length() - 1);
}

Expand Down

0 comments on commit 8618e28

Please sign in to comment.