patch for bad windows file paths

This commit is contained in:
Michael Peter Christen 2015-07-10 17:14:14 +02:00
parent 0aa6fcf259
commit e5b6424eed

View File

@ -271,12 +271,16 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
// file://localhost/c:/WINDOWS/clock.avi
// network file://hostname/path/to/the%20file.txt
// local file:///c:/path/to/the%20file.txt
final String h = url.substring(p + 1);
String h = url.substring(p + 1);
this.host = null; // host is ignored on file: protocol
if (h.startsWith("///")) { //absolute local file path
// no host given
this.path = h.substring(2); // "/path" or "/c:/path"
} else if (h.startsWith("//")) { // "//host/path" or "//host/c:/path"
if (h.charAt(3) == ':' && h.charAt(4) != '/' && h.charAt(4) != '\\') {
// wrong windows path, after the doublepoint there should be a backslash
h = h.substring(0, 4) + '\\' + h.substring(4);
}
int q = h.indexOf('/', 2);
if (q < 0) {
this.path = h.substring(2); // "path" or "c:/path"
@ -2317,7 +2321,8 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
*/
public static void main(final String[] args) {
final String[][] test = new String[][]{
new String[]{null, "file://Z:\\"},
new String[]{null, "file://Z:admin\\home"}, // thats wrong but may appear
new String[]{null, "file://Z:\\admin\\home"},
new String[]{null, "https://www.example.com/shoe/?p=2&ps=75#t={%22san_NaviPaging%22:2}"}, // ugly strange pagination link
new String[]{null, "C:WINDOWS\\CMD0.EXE"},
new String[]{null, "file://C:WINDOWS\\CMD0.EXE"},
@ -2388,7 +2393,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
((aURL != null) && (jURL != null) && (!(jURL.toString().equals(aURL.toNormalform(false)))))) {
System.out.println("Difference for environment=" + environment + ", url=" + url + ":");
System.out.println((jURL == null) ? "jURL rejected input" : "jURL=" + jURL.toString());
System.out.println((aURL == null) ? "aURL rejected input" : "aURL=" + aURL.toNormalform(false));
System.out.println((aURL == null) ? "aURL rejected input" : "aURL=" + aURL.toNormalform(false) + "; host=" + aURL.getHost() + "; path=" + aURL.getPath() + "; file=" + aURL.getFile());
}
// check stability: the normalform of the normalform must be equal to the normalform