Changeset 3701f71 for apps/jetty


Ignore:
Timestamp:
May 26, 2018 7:31:40 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2d7f0d3
Parents:
3f64825
Message:

Jetty: Skip files with [] in default servlet to avoid throwing exception

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/jetty/java/src/net/i2p/servlet/I2PDefaultServlet.java

    r3f64825 r3701f71  
    220220        for (int i=0 ; i< ls.length ; i++)
    221221        {
    222             Resource item = res.addPath(ls[i]);
     222            Resource item;
     223            try {
     224                item = res.addPath(ls[i]);
     225            } catch (IOException ioe) {
     226                System.out.println("Skipping file in directory listing: " + ioe.getMessage());
     227                continue;
     228            } catch (RuntimeException re) {
     229                // Jetty bug, addPath() argument must be unencoded,
     230                // but does not escape [],so it throws an unchecked exception:
     231                //
     232                // java.nio.file.InvalidPathException:
     233                // Illegal character in path at index xx: file:/home/.../[test].txt: [test].txt
     234                //   at org.eclipse.jetty.util.resource.FileResource.addPath(FileResource.java:213)
     235                //   ...
     236                //
     237                //  Catch here and continue so we show the rest of the listing,
     238                // and don't output the full path in the error page
     239                // TODO actually handle it
     240                System.out.println("Skipping file in directory listing: " + re.getMessage());
     241                continue;
     242            }
    223243           
    224244            buf.append("\n<TR><TD><A HREF=\"");
     
    232252            buf.append("\">");
    233253            buf.append(deTag(ls[i]));
    234             buf.append("&nbsp;");
    235254            buf.append("</A></TD><TD ALIGN=right>");
    236255            buf.append(item.length());
Note: See TracChangeset for help on using the changeset viewer.