NamedParameterUtils.parseSqlStatement should parse :{x} style parameter correctly

In my opinion, we should parse ":{x}" style parameter as "x" is parameter using "NamedParameterUtils.parseSqlStatement",
so the condition "j - i > 2" is the correct condition, not "j - i > 3", because if "i" is the index of
":" in ":{x}", and "j" is the index of "}" in ":{x}",  "j - i == 3" is true.
Also add a test case for SPR-16663.
This commit is contained in:
nkjackzhang
2018-03-29 11:57:33 +08:00
committed by Juergen Hoeller
parent f4813f5b4c
commit 82cb5dbf2b
2 changed files with 13 additions and 1 deletions

View File

@@ -130,7 +130,7 @@ public abstract class NamedParameterUtils {
throw new InvalidDataAccessApiUsageException(
"Non-terminated named parameter declaration at position " + i + " in statement: " + sql);
}
if (j - i > 3) {
if (j - i > 2) {
parameter = sql.substring(i + 2, j);
namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
totalParameterCount = addNamedParameter(parameterList, totalParameterCount, escapes, i, j + 1, parameter);