Skip to content
Permalink
Browse files

[FIXED JENKINS-16660] Allow variable names with dots in bracketed ref…

…erences.

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.
  • Loading branch information...
LarryNorth authored and kohsuke committed Jul 18, 2013
1 parent ba432da commit 3376cf01580ecd9cd099b5513874c8bed2490839
Showing with 7 additions and 2 deletions.
  1. +2 −2 core/src/main/java/hudson/Util.java
  2. +5 −0 core/src/test/java/hudson/UtilTest.java
@@ -112,9 +112,9 @@
}

/**
* 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 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", "$");
@@ -68,6 +69,10 @@ public void testReplaceMacro() {
assertEquals("asd$${AA}dd", Util.replaceMacro("asd$$$${AA}dd",m));
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));

0 comments on commit 3376cf0

Please sign in to comment.
You can’t perform that action at this time.