diff --git a/liquibase-core/src/main/java/liquibase/util/StringUtil.java b/liquibase-core/src/main/java/liquibase/util/StringUtil.java index bce27c06d77..3b10ea97fdc 100644 --- a/liquibase-core/src/main/java/liquibase/util/StringUtil.java +++ b/liquibase-core/src/main/java/liquibase/util/StringUtil.java @@ -159,7 +159,8 @@ protected static boolean isDelimiter(String piece, String previousPiece, String } else { if (endDelimiter.length() == 1) { if ("/".equals(endDelimiter)) { - if (previousPiece != null && previousPiece.endsWith("*")) { + if (previousPiece != null && !previousPiece.endsWith("\n")) { + //don't count /'s the are there for comments for division signs or any other use besides a / at the beginning of a line return false; } } diff --git a/liquibase-core/src/test/groovy/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParserTest.groovy b/liquibase-core/src/test/groovy/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParserTest.groovy index a41bcaa240a..9055d1c3abd 100644 --- a/liquibase-core/src/test/groovy/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParserTest.groovy +++ b/liquibase-core/src/test/groovy/liquibase/parser/core/formattedsql/FormattedSqlChangeLogParserTest.groovy @@ -165,9 +165,12 @@ END reany_procedure_name; grant /*Beware, this comment should not be seen as a delimiter! */ - execute on any_procedure_name to ANY_USER1/ -grant execute on any_procedure_name to ANY_USER2/ -grant execute on any_procedure_name to ANY_USER3/ + execute on any_procedure_name to ANY_USER1 +/ +grant execute on any_procedure_name to ANY_USER2 +/ +grant execute on any_procedure_name to ANY_USER3 +/ -- rollback drop PROCEDURE refresh_all_fos_permission_views/ """ @@ -695,13 +698,14 @@ not ignoreLines here changeLog.getChangeSets().size() == 1 changeLog.getChangeSets().get(0).getChanges().size() == 1 def statements = changeLog.getChangeSets().get(0).getChanges().get(0).generateStatements(new MockDatabase()) - statements.size() == 4 - statements[0].toString() == "CREATE OR REPLACE PROCEDURE any_procedure_name is\nBEGIN\n" + + statements*.toString() == [ + "CREATE OR REPLACE PROCEDURE any_procedure_name is\nBEGIN\n" + " DBMS_MVIEW.REFRESH('LEAD_INST_FOS_MV', method => '?', atomic_refresh => FALSE, out_of_place => true);\n" + - "END reany_procedure_name;" - statements[1].toString() == "grant \n execute on any_procedure_name to ANY_USER1" - statements[2].toString() == "grant execute on any_procedure_name to ANY_USER2" - statements[3].toString() == "grant execute on any_procedure_name to ANY_USER3" + "END reany_procedure_name;", + "grant \n execute on any_procedure_name to ANY_USER1", + "grant execute on any_procedure_name to ANY_USER2", + "grant execute on any_procedure_name to ANY_USER3", + ] } @Unroll("#featureName: #example") diff --git a/liquibase-core/src/test/groovy/liquibase/util/StringUtilTest.groovy b/liquibase-core/src/test/groovy/liquibase/util/StringUtilTest.groovy index d05db806738..c59304b002b 100644 --- a/liquibase-core/src/test/groovy/liquibase/util/StringUtilTest.groovy +++ b/liquibase-core/src/test/groovy/liquibase/util/StringUtilTest.groovy @@ -15,7 +15,7 @@ class StringUtilTest extends Specification { that Arrays.asList(StringUtil.processMultiLineSQL(rawString, stripComments, splitStatements, endDelimiter)), Matchers.contains(expected.toArray()) where: - stripComments | splitStatements | endDelimiter | rawString | expected + stripComments | splitStatements | endDelimiter | rawString | expected true | true | null | "/**\nSome comments go here\n**/\ncreate table sqlfilerollback (id int);\n\n/**\nSome morecomments go here\n**/\ncreate table sqlfilerollback2 (id int);" | ["create table sqlfilerollback (id int)", "create table sqlfilerollback2 (id int)"] true | true | null | "/*\nThis is a test comment of MS-SQL script\n*/\n\nSelect * from Test;\nUpdate Test set field = 1" | ["Select * from Test", "Update Test set field = 1"] true | true | null | "some sql/*Some text\nmore text*/more sql" | ["some sqlmore sql"] @@ -24,9 +24,14 @@ class StringUtilTest extends Specification { true | true | null | "/*\nThis is a test comment of SQL script\n*/\n\nSelect * from Test;\nUpdate Test set field = 1" | ["Select * from Test", "Update Test set field = 1"] true | true | null | "select * from simple_select_statement;\ninsert into table ( col ) values (' value with; semicolon ');" | ["select * from simple_select_statement", "insert into table ( col ) values (' value with; semicolon ')"] true | true | null | "--\n-- Create the blog table.\n--\nCREATE TABLE blog\n(\n ID NUMBER(15) NOT NULL\n)" | ["CREATE TABLE blog\n(\n ID NUMBER(15) NOT NULL\n)"] + true | true | null | "statement 1/2\n/\nstatement 2/2" | ["statement 1/2", "statement 2/2"] true | true | "//" | "drop procedure if exists my_proc//\n\ncreate procedure my_proc(i_myvar varchar)\nbegin\n a bunch of code here\nend//" | ["drop procedure if exists my_proc", "create procedure my_proc(i_myvar varchar)\nbegin\n a bunch of code here\nend"] true | true | "/" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;"] true | true | "/" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;\n/\nanother statement;here\n/\n" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;", "another statement;here"] + true | true | "/" | "statement 1/2\n/\nstatement 2/2" | ["statement 1/2", "statement 2/2"] + true | true | "/" | "/* a comment here */ statement 1/2\n/\nstatement 2/2" | ["statement 1/2", "statement 2/2"] + false | true | "/" | "/* a comment here */ statement 1/2\n/\nstatement 2/2" | ["/* a comment here */ statement 1/2", "statement 2/2"] + true | true | "/" | "/\nstatement here" | ["statement here"] true | true | "\\n/" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;\n/\nanother statement;here\n/\n" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;", "another statement;here"] true | true | "\\ngo" | "CREATE OR REPLACE PACKAGE emp_actions AS -- spec\nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;\nGO\nanother statement;here\nGO\n" | ["CREATE OR REPLACE PACKAGE emp_actions AS \nTYPE EmpRecTyp IS RECORD (emp_id INT, salary REAL);\nCURSOR desc_salary RETURN EmpRecTyp);\nEND emp_actions;", "another statement;here"] true | true | null | "statement 1;\nstatement 2;\nGO\n\nstatement 3; statement 4;" | ["statement 1", "statement 2", "statement 3", "statement 4"]