From eeae05289092ccca3388e18c5f439bd358159959 Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Wed, 28 Sep 2011 10:07:34 -0700 Subject: [PATCH] fix for bug where unclosed open braces in shell scripts (and other places where scriptbuilder Utils does its replacements) banjax parsing --- .../src/main/java/org/jclouds/scriptbuilder/util/Utils.java | 4 +++- .../test/java/org/jclouds/scriptbuilder/util/UtilsTest.java | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java index c550d63743..2a5f3bc66d 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/util/Utils.java @@ -62,7 +62,9 @@ public class Utils { } } - private static final Pattern pattern = Pattern.compile("\\{(.+?)\\}"); + /** matches any expression inside curly braces (where the expression does not including an open curly brace) */ + private static final Pattern pattern = Pattern.compile("\\{([^\\{]+?)\\}"); + /** * replaces tokens that are expressed as {token} diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/util/UtilsTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/util/UtilsTest.java index 1ca8184f26..dbcfc99ce7 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/util/UtilsTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/util/UtilsTest.java @@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals; import java.io.UnsupportedEncodingException; import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.scriptbuilder.domain.ShellToken; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; @@ -80,4 +81,9 @@ public class UtilsTest { "set HOST=\r\nset PORT=\r\n"); } + public void testSingleCurlyBraceDoesntBreakLfTokenReplacement() { + assertEquals(Utils.replaceTokens("{{lf}", ShellToken.tokenValueMap(OsFamily.UNIX)), + "{\n"); + } + }