Skip to content

Commit 0a13d6d

Browse files
committed
Cleanup URIUtil.toURI() for windows, document rationale behind each decision.
1 parent e664f31 commit 0a13d6d

File tree

1 file changed

+15
-1
lines changed
  • jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util

1 file changed

+15
-1
lines changed

jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,21 @@ public static URI toURI(String reference)
19321932
*/
19331933
URI uri = URI.create(reference);
19341934
if (uri.isAbsolute())
1935-
return uri;
1935+
{
1936+
// At this point we have a string detected as a URI.
1937+
// But that could also include Windows paths like "C:\path\to\foo.jar" or "C:/path/to/foo.jar"
1938+
String scheme = uri.getScheme();
1939+
if (scheme.length() == 1 && Character.isLetter(scheme.charAt(0)))
1940+
{
1941+
// Single character schemes are assumed to be windows.
1942+
// Make it a file: URI and process it separately.
1943+
return toURI("file:///" + uri.toASCIIString());
1944+
}
1945+
{
1946+
// Anything else, scheme wise, is acceptable.
1947+
return uri;
1948+
}
1949+
}
19361950
if (LOG.isDebugEnabled())
19371951
LOG.debug("Input string is detected as a non-absolute URI \"{}\"", reference);
19381952
throw new IllegalArgumentException("Non-absolute URI reference strings not supported");

0 commit comments

Comments
 (0)