Skip to content

Commit

Permalink
Added tests for thymeleaf/thymeleaf#809 on Spring 4 (SpEL)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfernandez committed Dec 14, 2020
1 parent d25fb15 commit 93a267f
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,23 @@ public void testSpringBaseConditionalComments() throws Exception {

}


@Test
public void testSpringBaseInstanceStaticRestrictions() throws Exception {

final SpringWebProcessingContextBuilder contextBuilder = new SpringWebProcessingContextBuilder();
contextBuilder.setApplicationContextConfigLocation(null);

final TestExecutor executor = TestExecutorFactory.createTestExecutor();
executor.setProcessingContextBuilder(contextBuilder);
executor.setDialects(Arrays.asList(new IDialect[] { SpringSpecificVersionUtils.createSpringStandardDialectInstance() }));
executor.setThrottleStep(this.throttleStep);
executor.execute("classpath:templateengine/springbase/instancestaticrestrictions");

Assert.assertTrue(executor.isAllOK());


}


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* =============================================================================
*
* Copyright (c) 2011-2016, The THYMELEAF team (http://www.thymeleaf.org)
*
* Licensed 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.thymeleaf.templateengine.springintegration.util;

import org.junit.Assert;
import org.junit.Test;
import org.thymeleaf.spring5.util.SpringStandardExpressionUtils;


public final class SpringStandardExpressionUtilsTest {



@Test
public void testcontainsSpELInstantiationOrStatic() {

Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abcnew"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abcnew "));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc3new "));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc_new "));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc$new "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc-new "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc new "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc.new "));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc newnew"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abcnew ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc new ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc new w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc new w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc (new )w ewnew"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc (new)w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("abc +new )w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("new "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("new "));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("newnew"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("new ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("new w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("new w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("(new )w ewnew"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("(new)w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("+new )w ewnew"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("!new )w ewnew"));

Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T()"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a)"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.SomeClass)"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.SomenewClass)"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.Some Class)"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.Some newClass)"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.Some new Class)"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.Some newClass)new"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("T(a.b.Some newClass)new "));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("newT(a.b.Some newClass)new"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("aT(a.b.Some newClass)a"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.Some newClass) a"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic(" aT(a.b.Some newClass)a "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a-T(a.b.SomeClass)a"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("aT(a.b.SomeClass)a"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.SomeClass) a"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic(" aT(a.b.SomeClass)a "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic(" a T(a.b.SomeClass)a "));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.SomeClass) a T(a.b.Some Class)"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.Some Class) a T(a.b.SomeClass)"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.Some Class) a T(a.b.Some Class)"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.SomeClass) )"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.SomeClass))"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.Some(Class) )"));
Assert.assertTrue(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.Some)Class) )"));
Assert.assertFalse(SpringStandardExpressionUtils.containsSpELInstantiationOrStatic("a T(a.b.Som(e)Class) )"));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:text="${new java.lang.String('hello')}">ALLOWED</p>
# ------------------------------------------------------------
%OUTPUT
<p>hello</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:text="${__${new java.lang.String('hello')}__}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:at0="${new java.lang.String('hello')}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:attr="at0=${new java.lang.String('hello')}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:href="~{${new java.lang.String('hello')}}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:insert="${new java.lang.String('hello')}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:text="@{${new java.lang.String('hello')}}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:text="${T(org.thymeleaf.TemplateEngine).TIMER_LOGGER_NAME}">ALLOWED</p>
# ------------------------------------------------------------
%OUTPUT
<p>org.thymeleaf.TemplateEngine.TIMER</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:text="${__${T(org.thymeleaf.TemplateEngine).TIMER_LOGGER_NAME}__}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:at0="${T(org.thymeleaf.TemplateEngine).TIMER_LOGGER_NAME}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:href="~{${T(org.thymeleaf.TemplateEngine).TIMER_LOGGER_NAME}}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TEMPLATE_MODE HTML
# ------------------------------------------------------------
%INPUT
<p th:text="@{${T(org.thymeleaf.TemplateEngine).TIMER_LOGGER_NAME}}">NOT ALLOWED</p>
# ------------------------------------------------------------
%EXCEPTION org.thymeleaf.exceptions.TemplateProcessingException
%EXCEPTION_MESSAGE_PATTERN (.*)\Qforbidden in this context\E(.*)

0 comments on commit 93a267f

Please sign in to comment.