DATACMNS-1683 - Rebuild quotation index from rewritten SpEL query.
We now use the correct quotation map that is based on the rewritten SpEL query to detect whether an expression was quoted. Previously, we used the quotation map from the original query. After augmenting the query with synthetic parameters, the quotation offset no longer matched the query that ß∑was under inspection and calls to SpelExtractor.isQuoted(…) could report an improper result. Original pull request: #434.
This commit is contained in:
committed by
Jens Schauder
parent
69e6958aa2
commit
f047743cfa
@@ -23,14 +23,15 @@ import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SpelQueryContext}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SpelQueryContextUnitTests {
|
||||
|
||||
static final QueryMethodEvaluationContextProvider EVALUATION_CONTEXT_PROVIDER = QueryMethodEvaluationContextProvider.DEFAULT;
|
||||
static final BiFunction<Integer, String, String> PARAMETER_NAME_SOURCE = (index, spel) -> "EPP" + index;
|
||||
static final BiFunction<Integer, String, String> PARAMETER_NAME_SOURCE = (index, spel) -> "__$synthetic$__" + index;
|
||||
static final BiFunction<String, String, String> REPLACEMENT_SOURCE = (prefix, name) -> prefix + name;
|
||||
|
||||
@Test // DATACMNS-1258
|
||||
@@ -63,4 +64,18 @@ public class SpelQueryContextUnitTests {
|
||||
|
||||
assertThat(context.withEvaluationContextProvider(EVALUATION_CONTEXT_PROVIDER)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1683
|
||||
public void reportsQuotationCorrectly() {
|
||||
|
||||
SpelQueryContext context = SpelQueryContext.of(PARAMETER_NAME_SOURCE, REPLACEMENT_SOURCE);
|
||||
|
||||
SpelQueryContext.SpelExtractor extractor = context.parse(
|
||||
"select n from NetworkServer n where (LOWER(n.name) LIKE LOWER(NULLIF(text(concat('%',:#{#networkRequest.name},'%')), '')) OR :#{#networkRequest.name} IS NULL )");
|
||||
|
||||
assertThat(extractor.getQueryString()).isEqualTo(
|
||||
"select n from NetworkServer n where (LOWER(n.name) LIKE LOWER(NULLIF(text(concat('%',:__$synthetic$__0,'%')), '')) OR :__$synthetic$__1 IS NULL )");
|
||||
assertThat(extractor.isQuoted(extractor.getQueryString().indexOf(":__$synthetic$__0"))).isFalse();
|
||||
assertThat(extractor.isQuoted(extractor.getQueryString().indexOf(":__$synthetic$__1"))).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user