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

Directory with dot not recognized correctly when loading data (breaks migration from 3.x to 4.x) #2066

Merged
merged 6 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ public InputStreamList openStreams(String relativeTo, String streamPath) throws
return returnList;
}

/**
* Generates a final path to <code>streamPath</code> relative to <code>relatoveTo</code>.
* If the last part of relativeTo contains a dot character (`.`)
* this part is considered to be a file name, if it does not, it is
* considered to be a directory.
* i.e.<br>
* <pre>
* changelog/some.sql -> some.sql is considered to be a file
* changelog/some_sql -> some_sql is considered to be a directory
* </pre>
*
* @param relativeTo starting point of the path resolution (may be null)
* @param streamPath a path to a resource relative to relativeTo must not be null
* @return a canonicalized absolute path to a resource
*/
protected String getFinalPath(String relativeTo, String streamPath) {
streamPath = streamPath.replace("\\", "/");
streamPath = streamPath.replaceFirst("^classpath\\*?:", "");
Expand All @@ -138,21 +153,25 @@ protected String getFinalPath(String relativeTo, String streamPath) {
relativeTo = relativeTo.replace("\\", "/");
relativeTo = relativeTo.replaceFirst("^classpath\\*?:", "");
relativeTo = relativeTo.replaceAll("//+", "/");
//
// If this is a simple file name then set the
// relativeTo value as if it is a root path
//
if (!relativeTo.contains("/") && relativeTo.contains(".")) {
relativeTo = "/";
}

//
// If this is not a simple file name and the last component
// of the path contains a '.' remove the last component
//
if (!relativeTo.endsWith("/")) {
String lastPortion = relativeTo.replaceFirst(".+/", "");
if (lastPortion.contains(".")) {
relativeTo = relativeTo.replaceFirst("/[^/]+?$", "");
}
}

//
// If this is a simple file name then set the
// relativeTo value as if it is a root path
//
if (!relativeTo.contains("/") && relativeTo.contains(".")) {
relativeTo = "/";
}
streamPath = relativeTo + "/" + streamPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ClassLoaderResourceAccessorTest extends Specification {
"com/example/other.file" | "/my/test.sql" | "com/example/my/test.sql"
"classpath:com/example/other.file" | "my/test.sql" | "com/example/my/test.sql"
"changelog.xml" | "sql/function.sql" | "sql/function.sql"
"db-change.log/changelog.xml" | "data/file.csv" | "db-change.log/data/file.csv"
}

@Unroll("#featureName: #relativeTo #streamPath")
Expand Down