Skip to content

Commit

Permalink
array_implode should only allow primitives for the glue
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Apr 19, 2016
1 parent ee08c2c commit d8fb301
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/core/ArgumentValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public static <T extends Construct> T getObject(Construct construct, Target t, S
* other types of Constructs. It also assumes that the class specified is
* tagged with a typeof annotation, thereby preventing the need for the
* expectedClassName like the deprecated version uses.
*
* This will work if the value is a subtype of the expected value.
*
* @param <T> The type expected.
* @param construct The generic object
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/laytonsmith/core/Static.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.laytonsmith.core.constructs.CInt;
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.CNumber;
import com.laytonsmith.core.constructs.CPrimitive;
import com.laytonsmith.core.constructs.CResource;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.CVoid;
Expand Down Expand Up @@ -248,7 +249,23 @@ public static byte getInt8(Construct c, Target t) {
public static boolean getBoolean(Construct c) {
return ArgumentValidation.getBoolean(c, Target.UNKNOWN);
}

/**
* Returns a primitive from any given construct.
* @param c
* @param t
* @return
*/
public static CPrimitive getPrimitive(Construct c, Target t){
return ArgumentValidation.getObject(c, t, CPrimitive.class);
}

/**
* Returns a CByteArray from any given construct.
* @param c
* @param t
* @return
*/
public static CByteArray getByteArray(Construct c, Target t) {
return ArgumentValidation.getByteArray(c, t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
CArray ca = (CArray) args[0];
String glue = " ";
if (args.length == 2) {
glue = args[1].val();
glue = Static.getPrimitive(args[1], t).val();
}
boolean first = true;
for (Construct key : ca.keySet()) {
Expand Down

0 comments on commit d8fb301

Please sign in to comment.