diff --git a/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java b/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java
index d4dac07e31b..04aad514f3f 100644
--- a/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java
+++ b/spring-test/src/test/java/org/springframework/test/jdbc/JdbcTestUtilsTests.java
@@ -48,6 +48,7 @@ public class JdbcTestUtilsTests {
@Mock
private JdbcTemplate jdbcTemplate;
+
@Test
public void containsDelimiters() {
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
@@ -117,6 +118,33 @@ public class JdbcTestUtilsTests {
assertEquals("statement 4 not split correctly", statement4, statements.get(3));
}
+ /**
+ * See SPR-10330
+ * @since 4.0
+ */
+ @Test
+ public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
+
+ EncodedResource resource = new EncodedResource(new ClassPathResource(
+ "test-data-with-comments-and-leading-tabs.sql", getClass()));
+ LineNumberReader lineNumberReader = new LineNumberReader(resource.getReader());
+
+ String script = JdbcTestUtils.readScript(lineNumberReader);
+
+ char delim = ';';
+ List statements = new ArrayList();
+ JdbcTestUtils.splitSqlScript(script, delim, statements);
+
+ String statement1 = "insert into customer (id, name) values (1, 'Sam Brannen')";
+ String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1)";
+ String statement3 = "insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1)";
+
+ assertEquals("wrong number of statements", 3, statements.size());
+ assertEquals("statement 1 not split correctly", statement1, statements.get(0));
+ assertEquals("statement 2 not split correctly", statement2, statements.get(1));
+ assertEquals("statement 3 not split correctly", statement3, statements.get(2));
+ }
+
@Test
public void deleteWithoutWhereClause() throws Exception {
given(jdbcTemplate.update("DELETE FROM person")).willReturn(10);
diff --git a/spring-test/src/test/resources/org/springframework/test/jdbc/test-data-with-comments-and-leading-tabs.sql b/spring-test/src/test/resources/org/springframework/test/jdbc/test-data-with-comments-and-leading-tabs.sql
new file mode 100644
index 00000000000..8f54e9eb7d2
--- /dev/null
+++ b/spring-test/src/test/resources/org/springframework/test/jdbc/test-data-with-comments-and-leading-tabs.sql
@@ -0,0 +1,9 @@
+-- The next comment line starts with a tab.
+ -- x, y, z...
+
+insert into customer (id, name)
+values (1, 'Sam Brannen');
+ -- This is also a comment with a leading tab.
+insert into orders(id, order_date, customer_id) values (1, '2013-06-08', 1);
+ -- This is also a comment with a leading tab, a space, and a tab.
+insert into orders(id, order_date, customer_id) values (2, '2013-06-08', 1);