Preserve square brackets for index/key expressions
Closes gh-27925
This commit is contained in:
@@ -68,7 +68,7 @@ abstract class NamedParameterUtils {
|
||||
* Set of characters that qualify as parameter separators,
|
||||
* indicating that a parameter name in an SQL String has ended.
|
||||
*/
|
||||
private static final String PARAMETER_SEPARATORS = "\"':&,;()|=+-*%/\\<>^[]";
|
||||
private static final String PARAMETER_SEPARATORS = "\"':&,;()|=+-*%/\\<>^]";
|
||||
|
||||
/**
|
||||
* An index with separator flags per character code.
|
||||
@@ -160,6 +160,9 @@ abstract class NamedParameterUtils {
|
||||
}
|
||||
if (j - i > 1) {
|
||||
parameter = sql.substring(i + 1, j);
|
||||
if (parameter.contains("[")) {
|
||||
parameter += "]"; // preserve end bracket for index/key
|
||||
}
|
||||
namedParameterCount = addNewNamedParameter(
|
||||
namedParameters, namedParameterCount, parameter);
|
||||
totalParameterCount = addNamedParameter(
|
||||
@@ -295,7 +298,6 @@ abstract class NamedParameterUtils {
|
||||
if (paramSource.hasValue(paramName)) {
|
||||
Parameter parameter = paramSource.getValue(paramName);
|
||||
if (parameter.getValue() instanceof Collection<?> c) {
|
||||
|
||||
Iterator<?> entryIter = c.iterator();
|
||||
int k = 0;
|
||||
int counter = 0;
|
||||
|
||||
@@ -277,6 +277,14 @@ public class NamedParameterUtilsUnitTests {
|
||||
assertThat(psql.getParameterNames()).containsExactly("ext");
|
||||
}
|
||||
|
||||
@Test // gh-27925
|
||||
void namedParamMapReference() {
|
||||
String sql = "insert into foos (id) values (:headers[id])";
|
||||
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
|
||||
assertThat(psql.getNamedParameterCount()).isEqualTo(1);
|
||||
assertThat(psql.getParameterNames()).containsExactly("headers[id]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowParsingMultipleUseOfParameter() {
|
||||
String sql = "SELECT * FROM person where name = :id or lastname = :id";
|
||||
|
||||
Reference in New Issue
Block a user