Skip to content

Commit

Permalink
Added type check to to_lower and to_upper.
Browse files Browse the repository at this point in the history
to_lower and to_upper used to stringify the argument passed to it. This change will
give a user an appropriate exception when passing anything else to the
function. If a player would like to stringify the argument anyways, he
could do that using the string() function.
  • Loading branch information
Pieter12345 committed Nov 14, 2015
1 parent 98b2d08 commit a3e76b6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/laytonsmith/core/functions/StringHandling.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public String docs() {

@Override
public ExceptionType[] thrown() {
return new ExceptionType[]{};
return new ExceptionType[]{ExceptionType.FormatException};
}

@Override
Expand All @@ -681,6 +681,10 @@ public Boolean runAsync() {

@Override
public Construct exec(Target t, Environment env, Construct... args) throws CancelCommandException, ConfigRuntimeException {
if (!(args[0] instanceof CString)) {
throw new ConfigRuntimeException(this.getName() + " expects a string as first argument, but type "
+ args[0].typeof() + " was found.", ExceptionType.FormatException, t);
}
return new CString(args[0].val().toUpperCase(), t);
}

Expand Down Expand Up @@ -720,7 +724,7 @@ public String docs() {

@Override
public ExceptionType[] thrown() {
return new ExceptionType[]{};
return new ExceptionType[]{ExceptionType.FormatException};
}

@Override
Expand All @@ -740,6 +744,10 @@ public Boolean runAsync() {

@Override
public Construct exec(Target t, Environment env, Construct... args) throws CancelCommandException, ConfigRuntimeException {
if (!(args[0] instanceof CString)) {
throw new ConfigRuntimeException(this.getName() + " expects a string as first argument, but type "
+ args[0].typeof() + " was found.", ExceptionType.FormatException, t);
}
return new CString(args[0].val().toLowerCase(), t);
}

Expand Down

0 comments on commit a3e76b6

Please sign in to comment.