Fix for ScriptUtils failure when '--' occurs inside a multi-line comment on the same line as '*/' (#22392)

* Test for multi-line comment block where the comment end delimiter occurs on a line starting with the single-line comment prefix
* ScriptUtils successfully parses a SQL script containing a multi-line comment block where the comment-end delimiter occurs on a line starting with the single-line comment prefix.
This commit is contained in:
Mansur Mustaquim
2019-02-08 20:20:51 +05:00
committed by Juergen Hoeller
parent a698adf125
commit 82dbde13b6
3 changed files with 48 additions and 8 deletions

View File

@@ -162,6 +162,20 @@ public class ScriptUtilsUnitTests {
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
}
@Test
public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception {
String script = readScript("test-data-with-multi-line-nested-comments.sql");
List<String> statements = new ArrayList<>();
splitSqlScript(script, ';', statements);
String statement1 = "INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller')";
String statement2 = "INSERT INTO users(first_name, last_name) VALUES( 'Sam' , 'Brannen' )";
assertEquals("wrong number of statements", 2, statements.size());
assertEquals("statement 1 not split correctly", statement1, statements.get(0));
assertEquals("statement 2 not split correctly", statement2, statements.get(1));
}
@Test
public void containsDelimiters() {
assertFalse(containsSqlScriptDelimiters("select 1\n select ';'", ";"));

View File

@@ -0,0 +1,23 @@
/* This is a multi line comment
* The next comment line has no text
* The next comment line starts with a space.
* x, y, z...
*/
INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller');
-- This is also a comment.
/*-------------------------------------------
-- A fancy multi-line comments that puts
-- single line comments inside of a multi-line
-- comment block.
Moreover, the block commend end delimiter
appears on a line that can potentially also
be a single-line comment if we weren't
already inside a multi-line comment run.
-------------------------------------------*/
INSERT INTO
users(first_name, last_name) -- This is a single line comment containing the block-end-comment sequence here */ but it's still a single-line comment
VALUES( 'Sam' -- first_name
, 'Brannen' -- last_name
);--