diff --git a/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java b/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java index d6f5e6ba07..8d9ab9bd08 100644 --- a/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java +++ b/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java @@ -399,10 +399,9 @@ public String relativize(MFile other) { if (getDelimiter() != null && getDelimiter().equals("/") && getDelimiter().equals(otherS3.getDelimiter()) && cdmS3Uri.getBucket().equals(otherS3.cdmS3Uri.getBucket())) { - final String key = getKey(); - final String otherKey = otherS3.getKey(); - return key == null || otherKey == null ? "" - : Paths.get("/" + key).relativize(Paths.get("/" + otherKey)).toString(); + final String key = getKey() == null ? "/" : "/" + getKey(); + final String otherKey = otherS3.getKey() == null ? "/" : "/" + otherS3.getKey(); + return Paths.get(key).relativize(Paths.get(otherKey)).toString(); } return ""; diff --git a/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java b/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java index 6334bdde53..6c7a2b1c07 100644 --- a/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java +++ b/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java @@ -525,6 +525,9 @@ public static List getTestParameters() { {"cdms3:bucket?a/long/#delimiter=/", "cdms3:bucket?a/long/key", ""}, {"cdms3:bucket", "cdms3:bucket?a/long/key", ""}, {"cdms3:bucket?a/long/key", "cdms3:bucket", ""}, + {"cdms3:bucket#delimiter=/", "cdms3:bucket?/#delimiter=/", ""}, + {"cdms3:bucket#delimiter=/", "cdms3:bucket?key/#delimiter=/", "key"}, + {"cdms3:bucket?key#delimiter=/", "cdms3:bucket?#delimiter=/", ".."}, {"cdms3:bucket?a/long/#delimiter=/", "cdms3:bucket?a/long/key/#delimiter=/", "key"}, {"cdms3:bucket?a/long/#delimiter=/", "cdms3:bucket?a/long/key#delimiter=/", "key"}, {"cdms3:bucket?a/long#delimiter=/", "cdms3:bucket?a/long/key/#delimiter=/", "key"},