diff --git a/src/main/java/com/laytonsmith/core/functions/DataHandling.java b/src/main/java/com/laytonsmith/core/functions/DataHandling.java index 94a9bee9d..5bdca5b26 100644 --- a/src/main/java/com/laytonsmith/core/functions/DataHandling.java +++ b/src/main/java/com/laytonsmith/core/functions/DataHandling.java @@ -2726,7 +2726,7 @@ public String docs() { @Override public ExceptionType[] thrown() { - return new ExceptionType[]{}; + return new ExceptionType[]{ExceptionType.IllegalArgumentException}; } @Override @@ -2736,7 +2736,7 @@ public boolean isRestricted() { @Override public boolean preResolveVariables() { - return false; + return true; } @Override @@ -2758,7 +2758,17 @@ public Construct exec(Target t, Environment environment, Construct... args) thro // return CVoid.VOID; // } else { //Mode 2 - String key = GetNamespace(args, null, getName(), t); + String key; + if(args.length == 1) { + if(!(args[0] instanceof CString)) { + throw new ConfigRuntimeException(this.getName() + " with 1 argument expects the argument to be a string.", + ExceptionType.IllegalArgumentException, t); + } + key = args[0].val(); + } else { + // Handle the deprecated syntax. + key = GetNamespace(args, null, getName(), t); + } return Globals.GetGlobalConstruct(key); // } } @@ -2818,7 +2828,7 @@ public String docs() { @Override public ExceptionType[] thrown() { - return new ExceptionType[]{ExceptionType.InsufficientArgumentsException}; + return new ExceptionType[]{ExceptionType.InsufficientArgumentsException, ExceptionType.IllegalArgumentException}; } @Override @@ -2828,7 +2838,7 @@ public boolean isRestricted() { @Override public boolean preResolveVariables() { - return false; + return true; } @Override @@ -2851,12 +2861,22 @@ public Construct exec(Target t, Environment environment, Construct... args) thro // throw new ConfigRuntimeException("Expecting a IVariable when only one parameter is specified", ExceptionType.InsufficientArgumentsException, t); // } // } else { - String key = GetNamespace(args, args.length - 1, getName(), t); - Construct c = args[args.length - 1]; - //We want to store the value contained, not the ivar itself - while (c instanceof IVariable) { - c = environment.getEnv(GlobalEnv.class).GetVarList().get(((IVariable) c).getName(), t).ival(); + String key; + if(args.length == 2) { + if(!(args[0] instanceof CString)) { + throw new ConfigRuntimeException(this.getName() + " with 2 arguments expects the first argument to be a string.", + ExceptionType.IllegalArgumentException, t); + } + key = args[0].val(); + } else { + // Handle the deprecated syntax. + key = GetNamespace(args, args.length - 1, getName(), t); } + Construct c = args[args.length - 1]; +// //We want to store the value contained, not the ivar itself +// while (c instanceof IVariable) { +// c = environment.getEnv(GlobalEnv.class).GetVarList().get(((IVariable) c).getName(), t).ival(); +// } Globals.SetGlobal(key, c); // } return CVoid.VOID; diff --git a/src/test/java/com/laytonsmith/core/functions/DataHandlingTest.java b/src/test/java/com/laytonsmith/core/functions/DataHandlingTest.java index abde2c3ff..f51dc886a 100644 --- a/src/test/java/com/laytonsmith/core/functions/DataHandlingTest.java +++ b/src/test/java/com/laytonsmith/core/functions/DataHandlingTest.java @@ -339,6 +339,21 @@ public void testExportImportWithProcs2() throws Exception{ + "msg(_get())", fakePlayer); verify(fakePlayer).sendMessage("{1, 2}"); } + + @Test + public void testExportImportIvarValue() throws Exception{ + when(fakePlayer.isOp()).thenReturn(Boolean.TRUE); + SRun("assign(@key, 'key1')" + + "assign(@value, 'key1Value')" + + "export(@key, @value)" + + "msg(import('key1'))", fakePlayer); + verify(fakePlayer).sendMessage("key1Value"); + SRun("assign(@key, 'key2')" + + "assign(@value, 'key2Value')" + + "export('key2', @value)" + + "msg(import(@key))", fakePlayer); + verify(fakePlayer).sendMessage("key2Value"); + } @Test(timeout = 10000) public void testIsBoolean() throws Exception {