This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/struts.git
commit 2f3d33aead040b9244ba2b76c563cf081d80370f Author: Yasser Zamani <yasserzam...@apache.org> AuthorDate: Fri Jun 29 16:28:23 2018 +0430 add an extra unit test --- .../com/opensymphony/xwork2/ognl/OgnlUtil.java | 9 ++-- .../xwork2/ognl/OgnlUtilStrutsTest.java | 56 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java index 12d3ed1..4832224 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java @@ -101,7 +101,8 @@ public class OgnlUtil { @Inject(value = XWorkConstants.OGNL_EXCLUDED_CLASSES, required = false) public void setExcludedClasses(String commaDelimitedClasses) { - Set<Class<?>> excludedClasses = this.excludedClasses; + Set<Class<?>> excludedClasses = new HashSet<>(); + excludedClasses.addAll(this.excludedClasses); excludedClasses.addAll(parseExcludedClasses(commaDelimitedClasses)); this.excludedClasses = Collections.unmodifiableSet(excludedClasses); } @@ -123,7 +124,8 @@ public class OgnlUtil { @Inject(value = XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAME_PATTERNS, required = false) public void setExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) { - Set<Pattern> excludedPackageNamePatterns = this.excludedPackageNamePatterns; + Set<Pattern> excludedPackageNamePatterns = new HashSet<>(); + excludedPackageNamePatterns.addAll(this.excludedPackageNamePatterns); excludedPackageNamePatterns.addAll(parseExcludedPackageNamePatterns(commaDelimitedPackagePatterns)); this.excludedPackageNamePatterns = Collections.unmodifiableSet(excludedPackageNamePatterns); } @@ -141,7 +143,8 @@ public class OgnlUtil { @Inject(value = XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAMES, required = false) public void setExcludedPackageNames(String commaDelimitedPackageNames) { - Set<String> excludedPackageNames = this.excludedPackageNames; + Set<String> excludedPackageNames = new HashSet<>(); + excludedPackageNames.addAll(this.excludedPackageNames); excludedPackageNames.addAll(parseExcludedPackageNames(commaDelimitedPackageNames)); this.excludedPackageNames = Collections.unmodifiableSet(excludedPackageNames); } diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java new file mode 100644 index 0000000..bd371dd --- /dev/null +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java @@ -0,0 +1,56 @@ +/* + * 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 com.opensymphony.xwork2.ognl; + +import org.apache.struts2.StrutsInternalTestCase; + +public class OgnlUtilStrutsTest extends StrutsInternalTestCase { + + private OgnlUtil ognlUtil; + + @Override + public void setUp() throws Exception { + super.setUp(); + ognlUtil = container.getInstance(OgnlUtil.class); + } + + public void testDefaultExcludes() { + ognlUtil.setExcludedClasses(""); + ognlUtil.setExcludedPackageNames(""); + ognlUtil.setExcludedPackageNamePatterns(""); + assertTrue(ognlUtil.getExcludedClasses().size() > 0); + assertTrue(ognlUtil.getExcludedPackageNames().size() > 0); + + try { + ognlUtil.getExcludedClasses().clear(); + } catch (Exception ex){ + assertTrue(ex instanceof UnsupportedOperationException); + } + try { + ognlUtil.getExcludedPackageNames().clear(); + } catch (Exception ex){ + assertTrue(ex instanceof UnsupportedOperationException); + } + try { + ognlUtil.getExcludedPackageNamePatterns().clear(); + } catch (Exception ex){ + assertTrue(ex instanceof UnsupportedOperationException); + } + } +}