Skip to content

Commit

Permalink
decode URL encoded path in DirectoryPathHandler (DAT-15154) (#4533)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenMassaro committed Aug 2, 2023
1 parent b59bdcb commit eb14106
Showing 1 changed file with 12 additions and 0 deletions.
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);
}
return new DirectoryResourceAccessor(new File(root));
}

Expand Down

0 comments on commit eb14106

Please sign in to comment.