Skip to content

Commit

Permalink
Merge expression-processor/master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanhb committed May 17, 2017
2 parents 71de612 + 0ce6e87 commit f370e52
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -64,7 +63,7 @@ class ExpressionProcessorTests {
void parse() {

def expression = expressionProcessor.parse('${1 + 1}')
assertTrue(expression instanceof VariableExpression)
assert expression instanceof VariableExpression
}

/**
Expand All @@ -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
}
}

/**
Expand All @@ -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'
}

/**
Expand All @@ -115,7 +130,7 @@ class ExpressionProcessorTests {
void process() {

def result = expressionProcessor.process('${1 + 1}')
assertEquals(2, result)
assert result == 2
}

/**
Expand All @@ -125,6 +140,6 @@ class ExpressionProcessorTests {
void processAsString() {

def resultAsString = expressionProcessor.processAsString('${1 + 1}')
assertEquals('2', resultAsString)
assert resultAsString == '2'
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@
<name>nz/net/ultraq/thymeleaf/expressions/</name>
<manifestEntries>
<Implementation-Title>Thymeleaf Expression Processor</Implementation-Title>
<Implementation-Version>1.1.2</Implementation-Version>
<Implementation-Version>1.1.3</Implementation-Version>
<Specification-Title>Thymeleaf Expression Processor</Specification-Title>
<Specification-Version>1.1.2</Specification-Version>
<Specification-Version>1.1.3</Specification-Version>
</manifestEntries>
</manifestSection>
</manifestSections>
Expand Down

0 comments on commit f370e52

Please sign in to comment.