You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ku...@apache.org on 2023/10/05 17:17:42 UTC
[struts] 01/02: WW-5340 Mild refactor StrutsOgnlGuard for easier subclassing
This is an automated email from the ASF dual-hosted git repository.
kusal pushed a commit to branch WW-5340-subclassable
in repository https://gitbox.apache.org/repos/asf/struts.git
commit 20eafb632721627b4bef2463e80b7dad42fd4dd6
Author: Kusal Kithul-Godage <gi...@kusal.io>
AuthorDate: Fri Oct 6 04:16:57 2023 +1100
WW-5340 Mild refactor StrutsOgnlGuard for easier subclassing
---
.../org/apache/struts2/ognl/StrutsOgnlGuard.java | 36 ++++++++++++++--------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/core/src/main/java/org/apache/struts2/ognl/StrutsOgnlGuard.java b/core/src/main/java/org/apache/struts2/ognl/StrutsOgnlGuard.java
index 262aec362..0cb4d1d93 100644
--- a/core/src/main/java/org/apache/struts2/ognl/StrutsOgnlGuard.java
+++ b/core/src/main/java/org/apache/struts2/ognl/StrutsOgnlGuard.java
@@ -71,28 +71,38 @@ public class StrutsOgnlGuard implements OgnlGuard {
@Override
public boolean isParsedTreeBlocked(Object tree) {
- return containsExcludedNodeType(tree);
+ if (!(tree instanceof Node) || skipTreeCheck((Node) tree)) {
+ return false;
+ }
+ return recurseNodes((Node) tree);
}
- protected boolean containsExcludedNodeType(Object tree) {
- if (!(tree instanceof Node) || excludedNodeTypes.isEmpty()) {
- return false;
+ protected boolean skipTreeCheck(Node tree) {
+ return excludedNodeTypes.isEmpty();
+ }
+
+ protected boolean recurseNodes(Node node) {
+ if (checkNode(node)) {
+ return true;
+ }
+ for (int i = 0; i < node.jjtGetNumChildren(); i++) {
+ if (recurseNodes(node.jjtGetChild(i))) {
+ return true;
+ }
}
- return recurseExcludedNodeType((Node) tree);
+ return false;
+ }
+
+ protected boolean checkNode(Node node) {
+ return containsExcludedNodeType(node);
}
- protected boolean recurseExcludedNodeType(Node node) {
+ protected boolean containsExcludedNodeType(Node node) {
String nodeClassName = node.getClass().getName();
if (excludedNodeTypes.contains(nodeClassName)) {
LOG.warn("Expression contains blocked node type [{}]", nodeClassName);
return true;
- } else {
- for (int i = 0; i < node.jjtGetNumChildren(); i++) {
- if (recurseExcludedNodeType(node.jjtGetChild(i))) {
- return true;
- }
- }
- return false;
}
+ return false;
}
}