NIHVIVO-2470 Restore parameter type checking on DumpDirective and HelpDirective. Handle undefined variables by assigning value = "Undefined."
This commit is contained in:
parent
84f779238c
commit
d64d45d8e6
4 changed files with 21 additions and 7 deletions
|
@ -83,8 +83,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
METHOD("Method"),
|
METHOD("Method"),
|
||||||
NUMBER("Number"),
|
NUMBER("Number"),
|
||||||
SEQUENCE("Sequence"),
|
SEQUENCE("Sequence"),
|
||||||
STRING("String"),
|
STRING("String");
|
||||||
UNDEFINED("Undefined");
|
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
@ -128,7 +127,6 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
Map<String, Object> value = new HashMap<String, Object>();
|
Map<String, Object> value = new HashMap<String, Object>();
|
||||||
|
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
value.put(Key.TYPE.toString(), Type.UNDEFINED);
|
|
||||||
value.put(Key.VALUE.toString(), VALUE_UNDEFINED);
|
value.put(Key.VALUE.toString(), VALUE_UNDEFINED);
|
||||||
|
|
||||||
// TemplateMethodModel and TemplateDirectiveModel objects can only be
|
// TemplateMethodModel and TemplateDirectiveModel objects can only be
|
||||||
|
|
|
@ -37,7 +37,19 @@ public class DumpDirective extends BaseDumpDirective {
|
||||||
"The dump directive doesn't allow nested content.");
|
"The dump directive doesn't allow nested content.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String varName = params.get("var").toString();
|
Object o = params.get("var");
|
||||||
|
|
||||||
|
if ( o == null) {
|
||||||
|
throw new TemplateModelException(
|
||||||
|
"Must specify 'var' argument.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !(o instanceof SimpleScalar)) {
|
||||||
|
throw new TemplateModelException(
|
||||||
|
"Value of parameter 'var' must be a string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String varName = o.toString(); //((SimpleScalar)o).getAsString();
|
||||||
Map<String, Object> map = getTemplateVariableDump(varName, env);
|
Map<String, Object> map = getTemplateVariableDump(varName, env);
|
||||||
|
|
||||||
dump(TEMPLATE_DEFAULT, map, env);
|
dump(TEMPLATE_DEFAULT, map, env);
|
||||||
|
|
|
@ -41,7 +41,12 @@ public class HelpDirective extends BaseDumpDirective {
|
||||||
"Must specify 'for' argument.");
|
"Must specify 'for' argument.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String varName = params.get("var").toString();
|
if ( !(o instanceof SimpleScalar)) {
|
||||||
|
throw new TemplateModelException(
|
||||||
|
"Value of parameter 'for' must be a string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String varName = o.toString(); //((SimpleScalar)o).getAsString();
|
||||||
TemplateHashModel dataModel = env.getDataModel();
|
TemplateHashModel dataModel = env.getDataModel();
|
||||||
Object templateModel = dataModel.get(varName);
|
Object templateModel = dataModel.get(varName);
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,6 @@ public class DumpDirectiveTest {
|
||||||
Map<String, Object> dataModel = new HashMap<String, Object>();
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
||||||
|
|
||||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||||
expectedDumpValue.put(Key.TYPE.toString(), Type.UNDEFINED);
|
|
||||||
expectedDumpValue.put(Key.VALUE.toString(), BaseDumpDirective.VALUE_UNDEFINED);
|
expectedDumpValue.put(Key.VALUE.toString(), BaseDumpDirective.VALUE_UNDEFINED);
|
||||||
|
|
||||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue