diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99ff72c13..1c6d202a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -313,6 +313,11 @@ upcoming patches so they don't hold up the release.
locations.
+### 1.1.3
+ - `null` check before attempting to check a fragment expression, potential fix
+ for this issue over in the layout dialect:
+ https://github.com/ultraq/thymeleaf-layout-dialect/issues/151
+
### 1.1.2
- Relaxed the root element restriction when using the `LEGACYHTML5` template
mode due to the way the NekoHTML parser works on HTML fragments
diff --git a/Source/nz/net/ultraq/thymeleaf/expressions/ExpressionProcessor.java b/Source/nz/net/ultraq/thymeleaf/expressions/ExpressionProcessor.java
index 2ee841553..2ff4bc181 100644
--- a/Source/nz/net/ultraq/thymeleaf/expressions/ExpressionProcessor.java
+++ b/Source/nz/net/ultraq/thymeleaf/expressions/ExpressionProcessor.java
@@ -25,6 +25,7 @@
import org.thymeleaf.standard.expression.FragmentExpression;
import org.thymeleaf.standard.expression.IStandardExpression;
import org.thymeleaf.standard.expression.StandardExpressions;
+import org.thymeleaf.util.StringUtils;
/**
* A simplified API for working with Thymeleaf expressions.
@@ -70,7 +71,7 @@ public IStandardExpression parse(String expression) {
* @return A fragment expression.
*/
public FragmentExpression parseFragmentExpression(String expression) {
- if (!THYMELEAF_3_FRAGMENT_EXPRESSION.matcher(expression).matches()) {
+ if (!StringUtils.isEmpty(expression) && !THYMELEAF_3_FRAGMENT_EXPRESSION.matcher(expression).matches()) {
if (oldFragmentExpressions.add(expression)) {
logger.warn(
"Fragment expression \"{}\" is being wrapped as a Thymeleaf 3 fragment expression (~{...}) for backwards compatibility purposes. "
diff --git a/Tests/nz/net/ultraq/thymeleaf/expressions/tests/ExpressionProcessorTests.groovy b/Tests/nz/net/ultraq/thymeleaf/expressions/tests/ExpressionProcessorTests.groovy
index c929feb4c..9794d246b 100644
--- a/Tests/nz/net/ultraq/thymeleaf/expressions/tests/ExpressionProcessorTests.groovy
+++ b/Tests/nz/net/ultraq/thymeleaf/expressions/tests/ExpressionProcessorTests.groovy
@@ -25,7 +25,6 @@ import org.thymeleaf.TemplateEngine
import org.thymeleaf.context.ExpressionContext
import org.thymeleaf.standard.expression.FragmentExpression
import org.thymeleaf.standard.expression.VariableExpression
-import static org.junit.Assert.*
/**
* Tests for the expression processor module.
@@ -64,7 +63,7 @@ class ExpressionProcessorTests {
void parse() {
def expression = expressionProcessor.parse('${1 + 1}')
- assertTrue(expression instanceof VariableExpression)
+ assert expression instanceof VariableExpression
}
/**
@@ -76,13 +75,29 @@ class ExpressionProcessorTests {
def fragmentExpression
fragmentExpression = expressionProcessor.parseFragmentExpression('~{hello.html}')
- assertTrue(fragmentExpression instanceof FragmentExpression)
- assertEquals(fragmentExpression.templateName.execute(expressionContext), 'hello.html');
+ assert fragmentExpression instanceof FragmentExpression
+ assert fragmentExpression.templateName.execute(expressionContext) == 'hello.html'
// Backwards compatibility test
fragmentExpression = expressionProcessor.parseFragmentExpression('hello.html')
- assertTrue(fragmentExpression instanceof FragmentExpression)
- assertEquals('hello.html', fragmentExpression.templateName.execute(expressionContext));
+ assert fragmentExpression instanceof FragmentExpression
+ assert fragmentExpression.templateName.execute(expressionContext) == 'hello.html'
+ }
+
+ /**
+ * {@code null} testing of fragment expression parsing since it does
+ * operations on the expression before passing it to the parser.
+ */
+ @Test
+ void parseFragmentExpressionNull() {
+
+ try {
+ expressionProcessor.parseFragmentExpression(null)
+ assert false
+ }
+ catch (ex) {
+ assert ex instanceof IllegalArgumentException
+ }
}
/**
@@ -97,15 +112,15 @@ class ExpressionProcessorTests {
'blah',
1)
}''')
- assertTrue(fragmentExpression instanceof FragmentExpression)
- assertEquals('hello', fragmentExpression.templateName.execute(expressionContext))
+ assert fragmentExpression instanceof FragmentExpression
+ assert fragmentExpression.templateName.execute(expressionContext) == 'hello'
// Backwards compatibility test
fragmentExpression = expressionProcessor.parseFragmentExpression('''hello::fragment(
'blah',
1)''')
- assertTrue(fragmentExpression instanceof FragmentExpression)
- assertEquals('hello', fragmentExpression.templateName.execute(expressionContext))
+ assert fragmentExpression instanceof FragmentExpression
+ assert fragmentExpression.templateName.execute(expressionContext) == 'hello'
}
/**
@@ -115,7 +130,7 @@ class ExpressionProcessorTests {
void process() {
def result = expressionProcessor.process('${1 + 1}')
- assertEquals(2, result)
+ assert result == 2
}
/**
@@ -125,6 +140,6 @@ class ExpressionProcessorTests {
void processAsString() {
def resultAsString = expressionProcessor.processAsString('${1 + 1}')
- assertEquals('2', resultAsString)
+ assert resultAsString == '2'
}
}
diff --git a/pom.xml b/pom.xml
index 0bc3c83da..5e4c9e596 100644
--- a/pom.xml
+++ b/pom.xml
@@ -385,9 +385,9 @@
nz/net/ultraq/thymeleaf/expressions/
Thymeleaf Expression Processor
- 1.1.2
+ 1.1.3
Thymeleaf Expression Processor
- 1.1.2
+ 1.1.3