From 3701f71fc65509b9b58e15c870b51e89de083d73 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 26 May 2018 19:31:40 +0000 Subject: [PATCH] Jetty: Skip files with [] in default servlet to avoid throwing exception --- .../net/i2p/servlet/I2PDefaultServlet.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/jetty/java/src/net/i2p/servlet/I2PDefaultServlet.java b/apps/jetty/java/src/net/i2p/servlet/I2PDefaultServlet.java index acedad0d68..b6f5825836 100644 --- a/apps/jetty/java/src/net/i2p/servlet/I2PDefaultServlet.java +++ b/apps/jetty/java/src/net/i2p/servlet/I2PDefaultServlet.java @@ -219,7 +219,27 @@ public class I2PDefaultServlet extends DefaultServlet dfmt.setTimeZone(utc); for (int i=0 ; i< ls.length ; i++) { - Resource item = res.addPath(ls[i]); + Resource item; + try { + item = res.addPath(ls[i]); + } catch (IOException ioe) { + System.out.println("Skipping file in directory listing: " + ioe.getMessage()); + continue; + } catch (RuntimeException re) { + // Jetty bug, addPath() argument must be unencoded, + // but does not escape [],so it throws an unchecked exception: + // + // java.nio.file.InvalidPathException: + // Illegal character in path at index xx: file:/home/.../[test].txt: [test].txt + // at org.eclipse.jetty.util.resource.FileResource.addPath(FileResource.java:213) + // ... + // + // Catch here and continue so we show the rest of the listing, + // and don't output the full path in the error page + // TODO actually handle it + System.out.println("Skipping file in directory listing: " + re.getMessage()); + continue; + } buf.append("\n"); buf.append(deTag(ls[i])); - buf.append(" "); buf.append(""); buf.append(item.length()); buf.append(" bytes ");