diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 5b0f0aad083e3938fdc4da9cb843203f801483a1..772098e7e2ed548914e2981e433afbdff0f0de1f 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -7,6 +7,7 @@ import org.apache.tools.ant.taskdefs.Chmod; import org.apache.tools.ant.taskdefs.Copy; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -17,7 +18,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; -import java.io.ByteArrayInputStream; import java.net.InetAddress; import java.net.UnknownHostException; import java.security.DigestInputStream; @@ -54,35 +54,35 @@ public class Util { return r; } + /** + * Pattern for capturing variables. Either $xyz or ${xyz}, while ignoring "$$" + */ + private static final Pattern VARIABLE = Pattern.compile("(?properties.get('key'). * *

- * This is a rather naive implementation that causes somewhat unexpected - * behavior when the expansion contains other macros. + * Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.) + * */ public static String replaceMacro(String s, Map properties) { int idx=0; - while((idx=s.indexOf('$',idx))>=0) { - // identify the key - int end=idx+1; - while(end