Skip to content

Commit

Permalink
Core: Only trim trailing slash when warehouse location is not root pa…
Browse files Browse the repository at this point in the history
…th (#9619)

Co-authored-by: Abid Mohammed <[email protected]>
Co-authored-by: Eduard Tudenhoefner <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent af46487 commit defef48
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static String stripTrailingSlash(String path) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(path), "path must not be null or empty");

String result = path;
while (result.endsWith("/")) {
while (!result.endsWith("://") && result.endsWith("/")) {
result = result.substring(0, result.length() - 1);
}
return result;
Expand Down
26 changes: 26 additions & 0 deletions core/src/test/java/org/apache/iceberg/util/TestLocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,30 @@ public void testStripTrailingSlashWithInvalidPath() {
.hasMessage("path must not be null or empty");
}
}

@Test
void testDoNotStripTrailingSlashForRootPath() {
String rootPath = "blobstore://";
assertThat(LocationUtil.stripTrailingSlash(rootPath))
.as("Should be root path")
.isEqualTo(rootPath);
}

@Test
void testStripTrailingSlashForRootPathWithTrailingSlash() {
String rootPath = "blobstore://";
String rootPathWithTrailingSlash = rootPath + "/";
assertThat(LocationUtil.stripTrailingSlash(rootPathWithTrailingSlash))
.as("Should be root path")
.isEqualTo(rootPath);
}

@Test
void testStripTrailingSlashForRootPathWithTrailingSlashes() {
String rootPath = "blobstore://";
String rootPathWithMultipleTrailingSlash = rootPath + "///";
assertThat(LocationUtil.stripTrailingSlash(rootPathWithMultipleTrailingSlash))
.as("Should be root path")
.isEqualTo(rootPath);
}
}

0 comments on commit defef48

Please sign in to comment.