提交 3376cf01 编写于 作者: L Larry North 提交者: Kohsuke Kawaguchi

[FIXED JENKINS-16660] Allow variable names with dots in bracketed references.

Given these <variable,value> mappings: <A,a> and <A.B,a-b>, $A.B would
evaluate to $a.B, as it currently does, and ${A.B} to a-b instead of the
current ${A.B}.

Existing ${A.B}-like references will break (not evaluate to ${A.B}) if
there actually is an A.B variable defined, which I think is very
unlikely.
上级 ba432da2
......@@ -112,9 +112,9 @@ public class Util {
}
/**
* Pattern for capturing variables. Either $xyz or ${xyz}, while ignoring "$$"
* Pattern for capturing variables. Either $xyz, ${xyz} or ${a.b} but not $a.b, while ignoring "$$"
*/
private static final Pattern VARIABLE = Pattern.compile("\\$([A-Za-z0-9_]+|\\{[A-Za-z0-9_]+\\}|\\$)");
private static final Pattern VARIABLE = Pattern.compile("\\$([A-Za-z0-9_]+|\\{[A-Za-z0-9_.]+\\}|\\$)");
/**
* Replaces the occurrence of '$key' by <tt>properties.get('key')</tt>.
......
......@@ -50,6 +50,7 @@ public class UtilTest {
public void testReplaceMacro() {
Map<String,String> m = new HashMap<String,String>();
m.put("A","a");
m.put("A.B","a-b");
m.put("AA","aa");
m.put("B","B");
m.put("DOLLAR", "$");
......@@ -69,6 +70,10 @@ public class UtilTest {
assertEquals("$", Util.replaceMacro("$$",m));
assertEquals("$$", Util.replaceMacro("$$$$",m));
// dots
assertEquals("a.B", Util.replaceMacro("$A.B", m));
assertEquals("a-b", Util.replaceMacro("${A.B}", m));
// test that more complex scenarios work
assertEquals("/a/B/aa", Util.replaceMacro("/$A/$B/$AA",m));
assertEquals("a-aa", Util.replaceMacro("$A-$AA",m));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册