55import java .net .URL ;
66import java .net .URLConnection ;
77import java .net .URLStreamHandler ;
8+ import java .util .ArrayList ;
9+ import java .util .Arrays ;
10+ import java .util .List ;
811
912import org .python .util .PythonInterpreter ;
1013
@@ -23,22 +26,25 @@ private static class JarExample {
2326 final String urlClassPath ;
2427 final String filePath ;
2528
29+ /** This constructor adapts unixPath to Windows when on Windows. */
2630 JarExample (String urlJarPath , String urlClassPath , String unixPath ) {
31+ this (urlJarPath , urlClassPath ,
32+ Platform .IS_WINDOWS ? new File (unixPath ).toString () : unixPath , true );
33+ }
34+
35+ /** This constructor accepts filePath exactly as given. */
36+ JarExample (String urlJarPath , String urlClassPath , String filePath , boolean ignored ) {
2737 this .urlJarPath = urlJarPath ;
2838 this .urlClassPath = urlClassPath ;
29- if (Platform .IS_WINDOWS ) {
30- this .filePath = new File (unixPath ).toString ();
31- } else {
32- this .filePath = unixPath ;
33- }
39+ this .filePath = filePath ;
3440 }
3541 }
3642
3743 /**
3844 * Examples of URLs (just the path and class noise) and the reference answer. Provide the
3945 * reference answer like a Un*x path (forward slash).
4046 */
41- private static JarExample [] jarExamples = { //
47+ private static List < JarExample > jarExamples = Arrays . asList ( //
4248 // simple jar-file url
4349 new JarExample ("/some_dir/some.jar" , "a/package/with/A.class" , "/some_dir/some.jar" ),
4450 // jar-file url to decode
@@ -48,7 +54,38 @@ private static class JarExample {
4854 // Some characters should be encoded in the URL, but emerge as themselves in the path.
4955 new JarExample ("/n%c3%a5gon/katalog/r%c3%a4tt.jar" , "en/f%c3%b6rpackning/med/En.class" ,
5056 "/någon/katalog/rätt.jar" ) //
51- };
57+ );
58+
59+ /* Check drive-letter and UNC path handling if on Windows. */
60+ static {
61+ if (Platform .IS_WINDOWS ) {
62+ // Add some examples to the list (must be made mutable for that).
63+ jarExamples = new ArrayList <JarExample >(jarExamples );
64+
65+ // Drive-letter examples
66+ jarExamples .add (new JarExample ("/C:/some_dir/some.jar" , "a/package/with/A.class" ,
67+ "C:\\ some_dir\\ some.jar" , true ));
68+ jarExamples .add (new JarExample ("/E:/n%c3%a5gon/katalog/r%c3%a4tt.jar" , "med/En.class" ,
69+ "E:\\ någon\\ katalog\\ rätt.jar" , true ));
70+
71+ // Simple network file path (UNC path without controversial characters)
72+ String p = "/org/python/version.properies" ;
73+ String r = "\\ \\ localhost\\ shared\\ jython-dev.jar" ;
74+ // JAR UNC file resource URL as produced by File.getURL or getURI
75+ jarExamples .add (new JarExample ("////localhost/shared/jython-dev.jar" , p , r , true ));
76+ // JAR UNC file resource URL as produced by URLClassLoader.getResource
77+ jarExamples .add (new JarExample ("//localhost/shared/jython-dev.jar" , p , r , true ));
78+
79+ // Network file path (UNC path with a controversial characters)
80+ r = "\\ \\ localhost\\ shared\\ jy thon%dev.jar" ;
81+ // JAR UNC file resource URL based on (deprecated) File.getURL is invalid
82+ // jarExamples.add(new JarExample("//localhost/shared/jy thon%dev.jar", p, r, true));
83+ // JAR UNC file resource URL based on File.getURI
84+ jarExamples .add (new JarExample ("////localhost/shared/jy%20thon%25dev.jar" , p , r , true ));
85+ // JAR UNC file resource URL as produced by URLClassLoader.getResource
86+ jarExamples .add (new JarExample ("//localhost/shared/jy%20thon%25dev.jar" , p , r , true ));
87+ }
88+ }
5289
5390 /**
5491 * Test case for finding the path in the local file system of the file located by a JAR-file
0 commit comments