Skip to content

Commit

Permalink
[FIXED JENKINS-16660] Allow variable names with dots in bracketed ref…
Browse files Browse the repository at this point in the history
…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 27, 2013
1 parent ba432da commit 3376cf0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -112,9 +112,9 @@ public static <T> List<T> filter( List<?> base, Class<T> type ) {
}

/**
* 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>.
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/java/hudson/UtilTest.java
Expand Up @@ -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", "$");
Expand All @@ -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));
Expand Down

0 comments on commit 3376cf0

Please sign in to comment.