Skip to content

Commit

Permalink
normalize paths in DatabaseChangeLog using commons-io (DAT-17592) (#5888
Browse files Browse the repository at this point in the history
)
  • Loading branch information
StevenMassaro committed May 9, 2024
1 parent 65f2994 commit 55188e8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions liquibase-dist/expected-distribution-contents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
├── internal
│   └── lib
│   ├── commons-collections4.jar
│   ├── commons-io.jar
│   ├── commons-lang3.jar
│   ├── commons-text.jar
│   ├── h2.jar
Expand Down
1 change: 1 addition & 0 deletions liquibase-dist/src/main/archive/licenses/oss/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Apache 2.0 License
- org.apache.commons:commons-lang3
- org.apache.commons:commons-text
- org.apache.commons:commons-collections4
- commons-io:commons-io

BSD 2 Clause License
- org.hsqldb:hsqldb
Expand Down
5 changes: 5 additions & 0 deletions liquibase-standard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import liquibase.servicelocator.LiquibaseService;
import liquibase.util.FileUtil;
import liquibase.util.StringUtil;
import org.apache.commons.io.FilenameUtils;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -1086,7 +1087,15 @@ public static String normalizePath(String filePath) {
filePath = filePath.substring(1);
}

filePath = Paths.get(filePath).normalize().toString();
String normalized = FilenameUtils.normalizeNoEndSeparator(filePath);
/*
Commons IO will return null if the double dot has no parent path segment to work with. In this case,
we fall back to path normalization using Paths.get(), which might fail on Windows.
*/
if (normalized == null) {
normalized = Paths.get(filePath).normalize().toString();
}
filePath = normalized;

if (filePath.contains("\\")) {
filePath = filePath.replace("\\", "/");
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<liquibase-pro.version>0-SNAPSHOT</liquibase-pro.version>
<argLine></argLine>
<commons-lang3.version>3.14.0</commons-lang3.version>
<commons-io.version>2.16.1</commons-io.version>
<ant.version>1.10.14</ant.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<groovy.version>4.0.20</groovy.version>
Expand Down

0 comments on commit 55188e8

Please sign in to comment.