This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 4c20574bf3 [#8280]Improvement(GCSTokenProvider): handle empty uri path 
(#8326)
4c20574bf3 is described below

commit 4c20574bf38f7fcfcc854884eaca97a03a466f17
Author: Sambhavi Pandey <[email protected]>
AuthorDate: Fri Aug 29 03:38:45 2025 +0530

    [#8280]Improvement(GCSTokenProvider): handle empty uri path (#8326)
    
    ### What changes were proposed in this pull request?
    Handle the empty URI path in normalizeUriPath in GCSTokenProvider
    
    ### Why are the changes needed?
    Currently the method normalizeUriPath in GCSTokenProvider.java doesn't
    handle empty paths correctly.
    
    Fix: #8280
    
    ### Does this PR introduce _any_ user-facing change?
    NO
    
    
    ### How was this patch tested?
    Unit testing
---
 .../java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java    | 3 +++
 .../org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java     | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
 
b/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
index 51720438ae..f40f2ea49f 100644
--- 
a/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
+++ 
b/bundles/gcp/src/main/java/org/apache/gravitino/gcs/credential/GCSTokenProvider.java
@@ -146,6 +146,9 @@ public class GCSTokenProvider implements CredentialProvider 
{
   @VisibleForTesting
   // Remove the first '/', and append `/` if the path does not end with '/'.
   static String normalizeUriPath(String resourcePath) {
+    if (resourcePath.isEmpty() || "/".equals(resourcePath)) {
+      return "";
+    }
     if (resourcePath.startsWith("/")) {
       resourcePath = resourcePath.substring(1);
     }
diff --git 
a/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
 
b/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
index 66326fc2ba..9dfb7b6440 100644
--- 
a/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
+++ 
b/bundles/gcp/src/test/java/org/apache/gravitino/gcs/credential/TestGCSTokenProvider.java
@@ -53,7 +53,9 @@ public class TestGCSTokenProvider {
             "/a/b/", "a/b/",
             "/a/b", "a/b/",
             "a/b", "a/b/",
-            "a/b/", "a/b/");
+            "a/b/", "a/b/",
+            "/", "",
+            "", "");
 
     checkResults.forEach(
         (k, v) -> {

Reply via email to