This repository was archived by the owner on Jul 31, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
src/main/java/com/kttdevelopment/simplehttpserver/handler Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 66
77 <groupId >com.kttdevelopment</groupId >
88 <artifactId >simplehttpserver</artifactId >
9- <version >03.05.05 </version >
9+ <version >03.05.06 </version >
1010 <packaging >jar</packaging >
1111
1212 <url >https://github.com/Ktt-Development/simplehttpserver</url >
Original file line number Diff line number Diff line change 1818 * @see FileHandler
1919 * @see FileEntry
2020 * @since 02.00.00
21- * @version 03.05.04
21+ * @version 03.05.06
2222 * @author Ktt Development
2323 */
2424class DirectoryEntry {
@@ -248,12 +248,15 @@ public final File getFile(final String path){
248248 // if not top level directory or if not child of directory folder, then return null file
249249 if (!pabs .equals (dabs ) && (!isWalkthrough || !pabs .startsWith (dabs ))) return null ;
250250
251- final String fileName = new File (dabs + relative ).getName ();
251+ final File targetFile = Paths .get (dabs ,relative ).toFile ();
252+ final String fileName = targetFile .getParentFile () == null ? targetFile .getPath () : targetFile .getName ();
252253
253254 // for each file in parent directory, run adapter to find file that matches adapted name
254255 for (final File file : Objects .requireNonNullElse (parentFile .listFiles (), new File [0 ]))
255256 if (!file .isDirectory () && adapter .getName (file ).equals (fileName ))
256257 return file ;
258+ else if (file .isDirectory () && file .getName ().equals (fileName )) // directories are not subject to adapter names
259+ return file ;
257260 return null ;
258261 }
259262 }
@@ -275,7 +278,7 @@ public final byte[] getBytes(final String path){
275278 }else {
276279 try {
277280 final File file = Objects .requireNonNull (getFile (path )); // find if file allowed
278- return adapter .getBytes (file ,Files .readAllBytes (file .toPath ())); // adapt bytes here
281+ return ! file . isDirectory () ? adapter .getBytes (file ,Files .readAllBytes (file .toPath ())) : null ; // adapt bytes here
279282 }catch (final NullPointerException | IOException ignored ){
280283 return null ;
281284 }
You can’t perform that action at this time.
0 commit comments