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

nacx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git


The following commit(s) were added to refs/heads/master by this push:
     new bc43572d65 JCLOUDS-1630: Handle URI template properly with opened 
curve bracket (#199)
bc43572d65 is described below

commit bc43572d657956e013b094dfa08618c61a795e3d
Author: Maxim <gmaksim2...@gmail.com>
AuthorDate: Wed Mar 20 15:19:46 2024 +0100

    JCLOUDS-1630: Handle URI template properly with opened curve bracket (#199)
    
    Co-authored-by: Maksim_Hadalau <maksim_hada...@epam.com>
---
 core/src/main/java/org/jclouds/http/UriTemplates.java     | 11 +++++++++++
 core/src/test/java/org/jclouds/http/UriTemplatesTest.java |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/core/src/main/java/org/jclouds/http/UriTemplates.java 
b/core/src/main/java/org/jclouds/http/UriTemplates.java
index 77f6b80925..8ffad12e3f 100644
--- a/core/src/main/java/org/jclouds/http/UriTemplates.java
+++ b/core/src/main/java/org/jclouds/http/UriTemplates.java
@@ -38,6 +38,11 @@ public class UriTemplates {
          return template.toString(); // skip expansion if there's no valid 
variables set. ex. {a} is the first valid
       checkNotNull(variables, "variables for %s", template);
 
+      // if no variables provided - return template as is
+      if (variables.isEmpty()) {
+         return template;
+      }
+
       boolean inVar = false;
       StringBuilder var = new StringBuilder();
       StringBuilder builder = new StringBuilder();
@@ -72,6 +77,12 @@ public class UriTemplates {
                builder.append(c);
          }
       }
+
+      // if variables provided but, curve bracket is not closed - append 
remaining to the result
+      if (inVar) {
+         builder.append('{').append(var);
+      }
+
       return builder.toString();
    }
 }
diff --git a/core/src/test/java/org/jclouds/http/UriTemplatesTest.java 
b/core/src/test/java/org/jclouds/http/UriTemplatesTest.java
index 83c1f86651..f9c1a4198d 100644
--- a/core/src/test/java/org/jclouds/http/UriTemplatesTest.java
+++ b/core/src/test/java/org/jclouds/http/UriTemplatesTest.java
@@ -55,4 +55,11 @@ public class UriTemplatesTest {
    public void testJson() {
       assertEquals(expand("{\"key\":\"{variable}\"}", 
ImmutableMap.of("variable", "value")), "{\"key\":\"value\"}");
    }
+
+   public void testExpandWithOpenedCurveBracket() {
+      assertEquals(expand("/repos/folder with { brackets in a key", 
ImmutableMap.of()),
+              "/repos/folder with { brackets in a key");
+      assertEquals(expand("/repos/folder with {foo", ImmutableMap.of("foo", 
"var")),
+              "/repos/folder with {foo");
+   }
 }

Reply via email to