Merge pull request #81 from ahgittin/patterns-curly-braces

Issue 703: fix for bug where unclosed open braces in shell scripts banjax parsing
This commit is contained in:
Adrian Cole 2011-09-28 12:18:05 -07:00
commit d7bb1b7ae7
2 changed files with 9 additions and 1 deletions

View File

@ -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 <code>{token}</code> * replaces tokens that are expressed as <code>{token}</code>

View File

@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.ShellToken;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -80,4 +81,9 @@ public class UtilsTest {
"set HOST=\r\nset PORT=\r\n"); "set HOST=\r\nset PORT=\r\n");
} }
public void testSingleCurlyBraceDoesntBreakLfTokenReplacement() {
assertEquals(Utils.replaceTokens("{{lf}", ShellToken.tokenValueMap(OsFamily.UNIX)),
"{\n");
}
} }