Skip to content

Commit 598b125

Browse files
committed
Merge pull request #27 from trisberg/parameter-parsing
2 parents ff84419 + 9fb6e23 commit 598b125

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,12 +85,18 @@ public static ParsedSql parseSqlStatement(final String sql) {
8585
int escapes = 0;
8686
int i = 0;
8787
while (i < statement.length) {
88-
int skipToPosition = skipCommentsAndQuotes(statement, i);
89-
if (i != skipToPosition) {
90-
if (skipToPosition >= statement.length) {
88+
int skipToPosition = i;
89+
while (i < statement.length) {
90+
skipToPosition = skipCommentsAndQuotes(statement, i);
91+
if (i == skipToPosition) {
9192
break;
9293
}
93-
i = skipToPosition;
94+
else {
95+
i = skipToPosition;
96+
}
97+
}
98+
if (i >= statement.length) {
99+
break;
94100
}
95101
char c = statement[i];
96102
if (c == ':' || c == '&') {

org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterUtilsTests.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -268,4 +268,30 @@ public void variableAssignmentOperator() throws Exception {
268268
assertEquals(expectedSql, newSql);
269269
}
270270

271+
/*
272+
* SPR-8280
273+
*/
274+
@Test
275+
public void parseSqlStatementWithQuotedSingleQuote() {
276+
String sql = "SELECT ':foo'':doo', :xxx FROM DUAL";
277+
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
278+
assertEquals(1, psql.getTotalParameterCount());
279+
assertEquals("xxx", psql.getParameterNames().get(0));
280+
}
281+
282+
@Test
283+
public void parseSqlStatementWithQuotesAndCommentBefore() {
284+
String sql = "SELECT /*:doo*/':foo', :xxx FROM DUAL";
285+
ParsedSql psql = NamedParameterUtils.parseSqlStatement(sql);
286+
assertEquals(1, psql.getTotalParameterCount());
287+
assertEquals("xxx", psql.getParameterNames().get(0));
288+
}
289+
290+
@Test
291+
public void parseSqlStatementWithQuotesAndCommentAfter() {
292+
String sql2 = "SELECT ':foo'/*:doo*/, :xxx FROM DUAL";
293+
ParsedSql psql2 = NamedParameterUtils.parseSqlStatement(sql2);
294+
assertEquals(1, psql2.getTotalParameterCount());
295+
assertEquals("xxx", psql2.getParameterNames().get(0));
296+
}
271297
}

0 commit comments

Comments
 (0)