aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-22 09:23:54 (EST)
committerWinston Prakash2011-12-01 20:47:00 (EST)
commitb102d4bbc6d247d37e9debd76197f50b1050f7f8 (patch)
treec8f13010900ab41f6d49323d99714926978d19c7
parent5337df3cdc52f5e0bcde1ba4eb32837a556ccb4f (diff)
downloadorg.eclipse.hudson.core-b102d4bbc6d247d37e9debd76197f50b1050f7f8.zip
org.eclipse.hudson.core-b102d4bbc6d247d37e9debd76197f50b1050f7f8.tar.gz
org.eclipse.hudson.core-b102d4bbc6d247d37e9debd76197f50b1050f7f8.tar.bz2
Improve fix for Hudson-8209: allow to use '.' only in {} brakets
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/Util.java2
-rw-r--r--hudson-core/src/test/java/hudson/UtilTest.java16
2 files changed, 13 insertions, 5 deletions
diff --git a/hudson-core/src/main/java/hudson/Util.java b/hudson-core/src/main/java/hudson/Util.java
index ab051c8..ecafed5 100644
--- a/hudson-core/src/main/java/hudson/Util.java
+++ b/hudson-core/src/main/java/hudson/Util.java
@@ -127,7 +127,7 @@ public class Util {
/**
* Pattern for capturing variables. Either $xyz or ${xyz}, 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>.
diff --git a/hudson-core/src/test/java/hudson/UtilTest.java b/hudson-core/src/test/java/hudson/UtilTest.java
index 51834cd..71870e7 100644
--- a/hudson-core/src/test/java/hudson/UtilTest.java
+++ b/hudson-core/src/test/java/hudson/UtilTest.java
@@ -38,6 +38,8 @@ public class UtilTest extends TestCase {
m.put("B","B");
m.put("DOLLAR", "$");
m.put("ENCLOSED", "a${A}");
+ m.put("a.b", "xyz");
+ m.put("a.b.c", "xyz");
// longest match
assertEquals("aa",Util.replaceMacro("$AA",m));
@@ -53,15 +55,21 @@ public class UtilTest extends TestCase {
assertEquals("$", Util.replaceMacro("$$",m));
assertEquals("$$", Util.replaceMacro("$$$$",m));
- // test that . is a valid variable character
- assertEquals("a.b", Util.replaceMacro("a.b", m));
- assertEquals("ab", 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));
assertEquals("/a/foo/can/B/you-believe_aa~it?", Util.replaceMacro("/$A/foo/can/$B/you-believe_$AA~it?",m));
assertEquals("$$aa$Ba${A}$it", Util.replaceMacro("$$$DOLLAR${AA}$$B${ENCLOSED}$it",m));
+
+ //Test complex case related to Hudson-8209.
+
+ // test that . is a valid variable character
+ assertEquals("a.b", Util.replaceMacro("a.b", m));
+ assertEquals("ab", Util.replaceMacro("${A.B}", m));
+ assertEquals("xyz.c", Util.replaceMacro("${a.b}.c",m));
+ assertEquals("xyz.d", Util.replaceMacro("${a.b.c}.d",m));
+ //Java can't determine where key ends. So, '.' can be used only as part of the key and when enclosed into {}
+ assertEquals("a.b.c.d", Util.replaceMacro("$A.b.c.d",m));
}