Copilot commented on code in PR #397:
URL: https://github.com/apache/commons-jexl/pull/397#discussion_r2767432350
##########
src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java:
##########
@@ -299,14 +297,22 @@ protected Interpreter createInterpreter(final JexlContext
context, final Frame l
};
}
// otherwise...
- final int numChildren = script.jjtGetNumChildren();
- Object result = null;
- for (int i = 0; i < numChildren; i++) {
- final JexlNode child = script.jjtGetChild(i);
- result = child.jjtAccept(this, data);
- cancelCheck(child);
+ final Object[] stack = saveStack();
+ try {
+ return runScript(script, data);
+ } finally {
+ restoreStack(stack);
+ }
+ }
+
+ private Object[] saveStack() {
+ return frame != null && frame.stack != null? frame.stack.clone() :
null;
+ }
+
+ private void restoreStack(Object[] stack) {
Review Comment:
There is an extra space before null. Should be 'return null;' instead of
'return null;' (with two spaces).
##########
src/test/java/org/apache/commons/jexl3/Issues400Test.java:
##########
@@ -980,5 +981,91 @@ void test451() {
assertThrows(JexlException.Property.class,
() -> jexl451.createScript("o.class.classLoader",
"o").execute(null, new Object()));
}
+
+ @Test
+ void testIssue455a() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ String code = "name -> `${name +\n\t\f\r name}`";
+ JexlScript script = jexl.createScript(code);
+ Object o = script.execute(null, "Hello");
+ String ctl = "HelloHello";
+ Assertions.assertEquals(ctl, o);
+ }
+
+ @Test
+ void testIssue455b() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ String code = "name -> `${name}\n${name}`;";
+ JexlScript script = jexl.createScript(code);
+ Object o = script.execute(null, "Hello");
+ String ctl = "Hello\nHello";
+ Assertions.assertEquals(ctl, o);
+ }
+
+ @Test
+ void testIssue455c() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext context = new MapContext();
+ context.set("name", "Hello");
+ final JxltEngine jxlt = jexl.createJxltEngine();
+ final JxltEngine.Template template =
jxlt.createTemplate("<b>\n\t${name\n\t+\r\f name}\n</b>");
+ final StringWriter writer = new StringWriter();
+ template.evaluate(context, writer);
+ assertEquals("<b>\n\tHelloHello\n</b>", writer.toString());
+ }
+
+ @Test
+ void testIssue455d() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ // 'ref' contains 'greeting' which is the name of the variable to
expand
+ String code = "`#{${\nref\t}}\n#{${\rref\f}}`;";
+ JexlScript script = jexl.createScript(code, "ref", "greeting");
+ Object o = script.execute(null, "greeting", "Hello");
+ String ctl = "Hello\nHello";
+ Assertions.assertEquals(ctl, o);
+ }
+
+ @Test
+ void testIssue455e() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ // Evaluate nested immediate inside deferred at runtime using a
parameterized script
+ final String src = "(name, suffix) -> `#{name} Hello ${name} !
#{suffix}`";
+ final JexlScript script = jexl.createScript(src);
+ final Object result = script.execute(null, "World", "~");
+ Assertions.assertEquals("World Hello World ! ~", result);
+ }
+
+ @Test
+ void testIssue455f() {
Review Comment:
The visibility modifier 'public' is inconsistent with other test methods in
this file. Most test methods in this file use package-private visibility (no
explicit modifier), such as testIssue455a, testIssue455b, testIssue455c,
testIssue455d, testIssue455g, and testIssue455h. For consistency, this should
be 'void testIssue455f()' instead of 'public void testIssue455f()'.
##########
src/test/java/org/apache/commons/jexl3/Issues400Test.java:
##########
@@ -980,5 +981,91 @@ void test451() {
assertThrows(JexlException.Property.class,
() -> jexl451.createScript("o.class.classLoader",
"o").execute(null, new Object()));
}
+
+ @Test
+ void testIssue455a() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ String code = "name -> `${name +\n\t\f\r name}`";
+ JexlScript script = jexl.createScript(code);
+ Object o = script.execute(null, "Hello");
+ String ctl = "HelloHello";
+ Assertions.assertEquals(ctl, o);
+ }
+
+ @Test
+ void testIssue455b() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ String code = "name -> `${name}\n${name}`;";
+ JexlScript script = jexl.createScript(code);
+ Object o = script.execute(null, "Hello");
+ String ctl = "Hello\nHello";
+ Assertions.assertEquals(ctl, o);
+ }
+
+ @Test
+ void testIssue455c() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext context = new MapContext();
+ context.set("name", "Hello");
+ final JxltEngine jxlt = jexl.createJxltEngine();
+ final JxltEngine.Template template =
jxlt.createTemplate("<b>\n\t${name\n\t+\r\f name}\n</b>");
+ final StringWriter writer = new StringWriter();
+ template.evaluate(context, writer);
+ assertEquals("<b>\n\tHelloHello\n</b>", writer.toString());
+ }
+
+ @Test
+ void testIssue455d() {
+ final JexlEngine jexl = new JexlBuilder().create();
+ // 'ref' contains 'greeting' which is the name of the variable to
expand
+ String code = "`#{${\nref\t}}\n#{${\rref\f}}`;";
+ JexlScript script = jexl.createScript(code, "ref", "greeting");
+ Object o = script.execute(null, "greeting", "Hello");
+ String ctl = "Hello\nHello";
+ Assertions.assertEquals(ctl, o);
+ }
+
+ @Test
+ void testIssue455e() {
Review Comment:
The visibility modifier 'public' is inconsistent with other test methods in
this file. Most test methods in this file use package-private visibility (no
explicit modifier), such as testIssue455a, testIssue455b, testIssue455c,
testIssue455d, testIssue455g, and testIssue455h. For consistency, this should
be 'void testIssue455e()' instead of 'public void testIssue455e()'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]