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:
Mark Paluch
2020-03-16 15:22:01 +01:00
committed by Jens Schauder
parent 69e6958aa2
commit f047743cfa
2 changed files with 28 additions and 4 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.util.Assert;
*
* @author Jens Schauder
* @author Gerrit Meier
* @author Mark Paluch
* @since 2.1
*/
@RequiredArgsConstructor(staticName = "of")
@@ -145,7 +146,7 @@ public class SpelQueryContext {
/**
* Parses a query string, identifies the contained SpEL expressions, replaces them with bind parameters and offers a
* {@link Map} from those bind parameters to the spel expression.
* {@link Map} from those bind parameters to the SpEL expression.
* <p>
* The parser detects quoted parts of the query string and does not detect SpEL expressions inside such quoted parts
* of the query.
@@ -208,7 +209,9 @@ public class SpelQueryContext {
this.expressions = Collections.unmodifiableMap(expressions);
this.query = resultQuery.toString();
this.quotations = quotedAreas;
// recreate quotation map based on rewritten query.
this.quotations = new QuotationMap(this.query);
}
/**
@@ -220,6 +223,12 @@ public class SpelQueryContext {
return query;
}
/**
* Return whether the {@link #getQueryString() query} at {@code index} is quoted.
*
* @param index
* @return {@literal true} if quoted; {@literal false} otherwise.
*/
public boolean isQuoted(int index) {
return quotations.isQuoted(index);
}