Skip to content

Commit

Permalink
Fixed Formatted SQL "property" parsing (#3037)
Browse files Browse the repository at this point in the history
Formatted SQL parsing was trying to parse as "-- property" any comment line that had "property" in it
  • Loading branch information
nvoxland committed Jul 12, 2022
1 parent 127e8fd commit 6f1717f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Expand Up @@ -83,7 +83,7 @@ public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParame
RawSQLChange change = null;
Pattern changeLogPattern = Pattern.compile("\\-\\-\\s*liquibase formatted.*", Pattern.CASE_INSENSITIVE);
Pattern propertyPattern = Pattern.compile("\\s*\\-\\-[\\s]*property\\s+(.*:.*)\\s+(.*:.*).*", Pattern.CASE_INSENSITIVE);
Pattern altPropertyOneDashPattern = Pattern.compile("\\s*?[-]+.*property\\s.*", Pattern.CASE_INSENSITIVE);
Pattern altPropertyOneDashPattern = Pattern.compile("\\s*?[-]+\\s*property\\s.*", Pattern.CASE_INSENSITIVE);
Pattern changeSetPattern = Pattern.compile("\\s*\\-\\-[\\s]*changeset\\s+(\"[^\"]+\"|[^:]+):\\s*(\"[^\"]+\"|\\S+).*", Pattern.CASE_INSENSITIVE);
Pattern altChangeSetOneDashPattern = Pattern.compile("\\-[\\s]*changeset\\s.*", Pattern.CASE_INSENSITIVE);
Pattern altChangeSetNoOtherInfoPattern = Pattern.compile("\\s*\\-\\-[\\s]*changeset[\\s]*.*$", Pattern.CASE_INSENSITIVE);
Expand Down
Expand Up @@ -513,6 +513,61 @@ CREATE TABLE ALL_CAPS_TABLE_2 (
assert e.getMessage().toLowerCase().contains("-property name")
}

def "parse strings that contain keywords not at the beginning"() throws Exception {
when:
def changeLog = new MockFormattedSqlChangeLogParser("""
--liquibase formatted sql
--changeset example:1
not a property here
- not a property here
-- not a property here
not a changeset here
- not a changeset here
-- not a changeset here
not a rollback here
- not a rollback here
-- not a rollback here
not a precondition here
- not a precondition here
-- not a precondition here
not a comment here
- not a comment here
-- not a comment here
not validCheckSum here
- not validCheckSum here
-- not validCheckSum here
not ignoreLines here
- not ignoreLines here
-- not ignoreLines here
""".trim()).parse("asdf.sql", new ChangeLogParameters(), new JUnitResourceAccessor())

then:
StringUtil.standardizeLineEndings(((RawSQLChange) changeLog.getChangeSets()[0].getChanges()[0]).getSql().trim()) == StringUtil.standardizeLineEndings("""
not a property here
- not a property here
-- not a property here
not a changeset here
- not a changeset here
-- not a changeset here
not a rollback here
- not a rollback here
-- not a rollback here
not a precondition here
- not a precondition here
-- not a precondition here
not a comment here
- not a comment here
-- not a comment here
not validCheckSum here
- not validCheckSum here
-- not validCheckSum here
not ignoreLines here
- not ignoreLines here
-- not ignoreLines here
""".trim())
}

def parse_withComment() throws Exception {
when:
String changeLogWithComment = "--liquibase formatted sql\n\n" +
Expand Down

0 comments on commit 6f1717f

Please sign in to comment.