|
16 | 16 | import java.io.File; |
17 | 17 | import java.io.IOException; |
18 | 18 | import java.net.URI; |
19 | | -import java.net.URISyntaxException; |
20 | 19 | import java.net.URL; |
21 | 20 | import java.net.URLClassLoader; |
22 | 21 | import java.nio.charset.StandardCharsets; |
@@ -1919,28 +1918,39 @@ public static URI toURI(String reference) |
1919 | 1918 |
|
1920 | 1919 | try |
1921 | 1920 | { |
1922 | | - Path path = Path.of(reference).toAbsolutePath(); |
1923 | | - return path.toUri(); |
| 1921 | + /* Perform URI test first. |
| 1922 | + * We don't want to perform Path.of(String) first. |
| 1923 | + * |
| 1924 | + * Example: reference parameter is the String "file:///path/to/dir" |
| 1925 | + * |
| 1926 | + * On Unix, the Path.of(reference) will result in a relative directory reference |
| 1927 | + * that includes the "file:" portion in the path after the current working directory. |
| 1928 | + * You'll wind up with something like "file:///home/user/code/jetty/12.1.x/jetty-core/jetty-util/file:///path/to/dir" in this case |
| 1929 | + * |
| 1930 | + * On Windows, the Path.of(reference) will not allow a Path.of("file:///path/to/dir") to work. |
| 1931 | + * This is because there cannot be multi-character drive letters (yes, Windows is limited to only 26 drive letters max) |
| 1932 | + */ |
| 1933 | + URI uri = URI.create(reference); |
| 1934 | + if (uri.isAbsolute()) |
| 1935 | + return uri; |
| 1936 | + if (LOG.isDebugEnabled()) |
| 1937 | + LOG.debug("Input string is detected as a non-absolute URI \"{}\"", reference); |
| 1938 | + throw new IllegalArgumentException("Non-absolute URI reference strings not supported"); |
1924 | 1939 | } |
1925 | | - catch (InvalidPathException e) |
| 1940 | + catch (IllegalArgumentException e) |
1926 | 1941 | { |
1927 | | - // Not a path reference. |
1928 | | - LOG.trace("ignored", e); |
| 1942 | + LOG.trace("IGNORED: Invalid as URI Reference: {}", reference, e); |
1929 | 1943 | } |
1930 | 1944 |
|
1931 | 1945 | try |
1932 | 1946 | { |
1933 | | - URI uri = new URI(reference); |
1934 | | - if (uri.isAbsolute()) |
1935 | | - return uri; |
1936 | | - if (LOG.isDebugEnabled()) |
1937 | | - LOG.debug("Input string is detected as a non-absolute URI \"{}\"", reference); |
1938 | | - throw new IllegalArgumentException("Non-absolute URI reference strings not supported"); |
| 1947 | + Path path = Path.of(reference).toAbsolutePath(); |
| 1948 | + return path.toUri(); |
1939 | 1949 | } |
1940 | | - catch (URISyntaxException x) |
| 1950 | + catch (InvalidPathException e) |
1941 | 1951 | { |
1942 | | - // Not a URI reference either. |
1943 | | - LOG.trace("ignored", x); |
| 1952 | + // Not a path reference. |
| 1953 | + LOG.trace("IGNORED: Invalid as Path Reference: {}", reference, e); |
1944 | 1954 | } |
1945 | 1955 |
|
1946 | 1956 | // If we reached this here, that means the input string cannot be used as |
|
0 commit comments