You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2023/08/22 15:31:46 UTC
[commons-jexl] branch master updated: JEXL-402: update grammar (return with no arg nor semicol) - added test, updated inteerpreter
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push:
new 12c0a938 JEXL-402: update grammar (return with no arg nor semicol) - added test, updated inteerpreter
12c0a938 is described below
commit 12c0a9389f413ebdc9024ac7290aff7685df4034
Author: Henri Biestro <hb...@cloudera.com>
AuthorDate: Tue Aug 22 17:31:18 2023 +0200
JEXL-402: update grammar (return with no arg nor semicol)
- added test, updated inteerpreter
---
.../apache/commons/jexl3/internal/Interpreter.java | 4 +-
.../org/apache/commons/jexl3/parser/Parser.jjt | 2 +-
.../org/apache/commons/jexl3/Issues400Test.java | 64 ++++++++++++++++++++++
3 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
index 0ce648f7..5d3c0ce0 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
@@ -597,7 +597,9 @@ public class Interpreter extends InterpreterBase {
@Override
protected Object visit(final ASTReturnStatement node, final Object data) {
- final Object val = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object val = node.jjtGetNumChildren() == 1
+ ? node.jjtGetChild(0).jjtAccept(this, data)
+ : null;
cancelCheck(node);
throw new JexlException.Return(node, null, val);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
index cfa7a97e..1e286d9f 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
+++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
@@ -418,7 +418,7 @@ void DoWhileStatement() : {}
void ReturnStatement() : {}
{
- <RETURN> ExpressionStatement()
+ <RETURN> ( ExpressionStatement() )?
}
void Continue() #Continue : {
diff --git a/src/test/java/org/apache/commons/jexl3/Issues400Test.java b/src/test/java/org/apache/commons/jexl3/Issues400Test.java
new file mode 100644
index 00000000..81d2a56c
--- /dev/null
+++ b/src/test/java/org/apache/commons/jexl3/Issues400Test.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl3;
+
+import org.apache.commons.jexl3.internal.Engine32;
+import org.apache.commons.jexl3.internal.OptionsContext;
+import static org.apache.commons.jexl3.introspection.JexlPermissions.RESTRICTED;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.lang.reflect.Proxy;
+import java.math.MathContext;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.apache.commons.jexl3.internal.Util.debuggerCheck;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test cases for reported issue between JEXL-300 and JEXL-399.
+ */
+public class Issues400Test {
+
+ @Test
+ public void test402() {
+ final JexlContext jc = new MapContext();
+ final String[] sources = new String[]{
+ "if (true) { return }",
+ "if (true) { 3; return }",
+ "(x->{ 3; return })()"
+ };
+ final JexlEngine jexl = new JexlBuilder().create();
+ for (final String source : sources) {
+ final JexlScript e = jexl.createScript(source);
+ final Object o = e.execute(jc);
+ Assert.assertNull(o);
+ }
+ }
+}