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

decode URL encoded path in DirectoryPathHandler (DAT-15154) #4533

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package liquibase.resource;

import liquibase.Scope;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;

import static java.net.URLDecoder.*;

/**
* {@link PathHandler} that converts the path into a {@link DirectoryResourceAccessor}.
*/
Expand Down Expand Up @@ -33,6 +38,13 @@ public ResourceAccessor getResourceAccessor(String root) throws FileNotFoundExce
root = root
.replace("file:", "")
.replace("\\", "/");
try {
// Because this method is passed a URL from liquibase.resource.ClassLoaderResourceAccessor.configureAdditionalResourceAccessors,
// it should be decoded from its URL-encoded form.
root = decode(root, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
Scope.getCurrentScope().getLog(getClass()).fine("Failed to decode path " + root + "; continuing without decoding.", e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if it is a file:// url should we not suppress this error message as we did the replace above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 44 is primarily about removing things like %20 from the root and replacing them with a space. I think keeping the error message could be useful.

}
return new DirectoryResourceAccessor(new File(root));
}

Expand Down