@@ -93,18 +93,13 @@ private static class JarResourceURLProvider implements JarFileReference.JarFileC
9393 private static final JarResourceURLProvider INSTANCE = new JarResourceURLProvider ();
9494
9595 @ Override
96- public URL apply (JarFile jarFile , Path path , String res ) {
97- JarEntry entry = jarFile .getJarEntry (res );
96+ public URL apply (JarFile jarFile , Path path , String resource ) {
97+ JarEntry entry = jarFile .getJarEntry (resource );
9898 if (entry == null ) {
9999 return null ;
100100 }
101101 try {
102- String realName = JarEntries .getRealName (entry );
103- // Avoid ending the URL with / to avoid breaking compatibility
104- if (realName .endsWith ("/" )) {
105- realName = realName .substring (0 , realName .length () - 1 );
106- }
107- final URL resUrl = getUrl (path , realName );
102+ final URL resUrl = getUrl (path , getRealName (entry , resource ));
108103 // wrap it up into a "jar" protocol URL
109104 //horrible hack to deal with '?' characters in the URL
110105 //seems to be the only way, the URI constructor just does not let you handle them in a sane way
@@ -124,6 +119,25 @@ public URL apply(JarFile jarFile, Path path, String res) {
124119 }
125120 }
126121
122+ private static String getRealName (JarEntry entry , String resource ) {
123+ String realName = JarEntries .getRealName (entry );
124+ // Make sure directories are returned with a / when the resource was requested with a /
125+ if (resource .endsWith ("/" ) && entry .isDirectory ()) {
126+ if (realName .endsWith ("/" )) {
127+ return realName ;
128+ } else {
129+ return realName + "/" ;
130+ }
131+ }
132+
133+ // this shouldn't be necessary but the previous implementation was doing it forcibly so keeping it for safety
134+ if (realName .endsWith ("/" )) {
135+ return realName .substring (0 , realName .length () - 1 );
136+ }
137+
138+ return realName ;
139+ }
140+
127141 private static URL getUrl (Path jarPath , String realName ) throws MalformedURLException , URISyntaxException {
128142 final URI jarUri = jarPath .toUri ();
129143 // first create a URI which includes both the jar file path and the relative resource name
0 commit comments