Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Formatted SQL "property" parsing #3037

Merged
merged 2 commits into from Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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