Fix expansion
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@792577 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
index 8ec781e..7c17b12 100644
--- a/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
+++ b/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/shell/Closure.java
@@ -101,29 +101,37 @@
Object executeStatement(List<CharSequence> statement) throws Exception
{
- Object result;
- List<Object> values = new ArrayList<Object>();
- CharSequence statement0 = statement.remove(0);
-
// derek: FEATURE: add set -x facility if echo is set
if (Boolean.TRUE.equals(session.get("echo"))) {
StringBuilder buf = new StringBuilder("+ ");
- buf.append(statement0);
for (CharSequence token : statement)
{
- buf.append(' ');
+ if (buf.length() > 0)
+ {
+ buf.append(' ');
+ }
buf.append(token);
}
System.err.println(buf);
}
- Object cmd = eval(statement0);
+ Object result;
+ List<Object> values = new ArrayList<Object>();
for (CharSequence token : statement)
{
- values.add(eval(token));
+ Object v = eval(token);
+ if (v != null && v == parms)
+ {
+ for (Object p : parms)
+ {
+ values.add(p);
+ }
+ }
+ else {
+ values.add(v);
+ }
}
-
- result = execute(cmd, values);
+ result = execute(values.remove(0), values);
return result;
}
@@ -227,7 +235,21 @@
}
if (res != null)
{
- sb.append(res);
+ if (res == parms)
+ {
+ for (int i = 0; i < parms.size(); i++)
+ {
+ if (i > 0)
+ {
+ sb.append(' ');
+ }
+ sb.append(parms.get(i));
+ }
+ }
+ else
+ {
+ sb.append(res);
+ }
res = null;
}
if (start != p.current)
@@ -285,7 +307,17 @@
}
if (res != null)
{
- sb.append(res);
+ if (res == parms)
+ {
+ for (Object v : parms)
+ {
+ sb.append(v);
+ }
+ }
+ else
+ {
+ sb.append(res);
+ }
res = null;
}
sb.append(new Parser(p.text.subSequence(start, p.current)).unescape());
@@ -294,7 +326,21 @@
{
if (res != null)
{
- sb.append(res);
+ if (res == parms)
+ {
+ for (int i = 0; i < parms.size(); i++)
+ {
+ if (i > 0)
+ {
+ sb.append(' ');
+ }
+ sb.append(parms.get(i));
+ }
+ }
+ else
+ {
+ sb.append(res);
+ }
}
res = sb;
}
diff --git a/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java b/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
index 8d47c14..3e0e27b 100644
--- a/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
+++ b/gogo/runtime/src/test/java/org/apache/felix/gogo/runtime/shell/TestParser.java
@@ -63,6 +63,11 @@
assertEquals("aa", c.execute("echo $c$c | capture"));
assertEquals("a ;a", c.execute("echo a\\ \\;a | capture"));
assertEquals("baabab", c.execute("echo b${c}${c}b${c}b | capture"));
+
+ c.set("d", "a b ");
+ assertEquals("a b ", c.execute("echo \"$d\" | capture"));
+// assertEquals("a b", c.execute("echo $d | capture"));
+// assertEquals("a b", c.execute("echo <echo $d> | capture"));
}
public void testScope() throws Exception
@@ -123,7 +128,10 @@
assertEquals(5, c.execute("[1 2 [3 4] 5 6] size"));
assertEquals("a", c.execute("e = { echo $0 } ; <e a b | capture>"));
assertEquals("b", c.execute("e = { echo $1 } ; <e a b | capture>"));
- assertEquals("a b", c.execute("e = { echo $args } ; <e a b | capture>"));
+ assertEquals("b", c.execute("e = { $args } ; <e echo b | capture>"));
+ assertEquals("ca b", c.execute("e = { echo c$args } ; <e a b | capture>"));
+ assertEquals("c a b", c.execute("e = { echo c $args } ; <e a b | capture>"));
+ assertEquals("ca b", c.execute("e = { echo c$args } ; <e 'a b' | capture>"));
}
public void testArray() throws Exception