Encode paths for download more robustly.

This commit is contained in:
Michael Bayne
2017-02-12 07:38:30 -08:00
parent a5ad6edf3c
commit 84af080b0d
@@ -13,6 +13,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.FileLock; import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException; import java.nio.channels.OverlappingFileLockException;
@@ -1753,8 +1754,14 @@ public class Application
*/ */
protected static String encodePath (String path) protected static String encodePath (String path)
{ {
// URLEncoder is too fancy for paths, we want to keep / try {
return path.replace(" ", "%20"); // we want to keep slashes because we're encoding an entire path; also we need to turn
// + into %20 because web servers don't like + in paths or file names, blah
return URLEncoder.encode(path, "UTF-8").replace("%2F", "/").replace("+", "%20");
} catch (UnsupportedEncodingException ue) {
log.warning("Failed to URL encode " + path + ": " + ue);
return path;
}
} }
/** /**