]> WPIA git - gigi.git/blobdiff - lib/jetty/org/eclipse/jetty/util/resource/FileResource.java
updating jetty to jetty-9.2.16.v2016040
[gigi.git] / lib / jetty / org / eclipse / jetty / util / resource / FileResource.java
index 449884241b6fb5dd881d9c6f93086c146499205c..dbc4670a727a8184c159ce9ea574582bd41d42ee 100644 (file)
@@ -1,6 +1,6 @@
 //
 //  ========================================================================
-//  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
+//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
 //  ------------------------------------------------------------------------
 //  All rights reserved. This program and the accompanying materials
 //  are made available under the terms of the Eclipse Public License v1.0
@@ -29,10 +29,12 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.file.InvalidPathException;
 import java.nio.file.StandardOpenOption;
 import java.security.Permission;
 
 import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.StringUtil;
 import org.eclipse.jetty.util.URIUtil;
 import org.eclipse.jetty.util.log.Log;
 import org.eclipse.jetty.util.log.Logger;
@@ -65,6 +67,7 @@ public class FileResource extends Resource
         {
             // Try standard API to convert URL to file.
             file =new File(url.toURI());
+            assertValidPath(file.toString());
         }
         catch (URISyntaxException e) 
         {
@@ -98,7 +101,7 @@ public class FileResource extends Resource
         
         _file=file;
         _uri=normalizeURI(_file,url.toURI());
-        _alias=checkAlias(_file);
+        _alias=checkFileAlias(_file);
     }
 
     /* -------------------------------------------------------- */
@@ -108,25 +111,22 @@ public class FileResource extends Resource
         _file=file;
         URI file_uri=_file.toURI();
         _uri=normalizeURI(_file,uri);
-        
-        if (!_uri.equals(file_uri.toString()))
-        {
-            // URI and File URI are different.  Is it just an encoding difference?
-            if (!file_uri.toString().equals(URIUtil.decodePath(uri.toString())))
-                 _alias=_file.toURI();
-            else
-                _alias=checkAlias(_file);
-        }
+        assertValidPath(file.toString());
+
+        // Is it a URI alias?
+        if (!URIUtil.equalsIgnoreEncodings(_uri,file_uri.toString()))
+            _alias=_file.toURI();
         else
-            _alias=checkAlias(_file);
+            _alias=checkFileAlias(_file);
     }
 
     /* -------------------------------------------------------- */
     FileResource(File file)
     {
+        assertValidPath(file.toString());
         _file=file;
         _uri=normalizeURI(_file,_file.toURI());
-        _alias=checkAlias(_file);
+        _alias=checkFileAlias(_file);
     }
 
     /* -------------------------------------------------------- */
@@ -144,7 +144,7 @@ public class FileResource extends Resource
     }
 
     /* -------------------------------------------------------- */
-    private static URI checkAlias(File file)
+    private static URI checkFileAlias(File file)
     {
         try
         {
@@ -153,7 +153,8 @@ public class FileResource extends Resource
 
             if (!abs.equals(can))
             {
-                LOG.debug("ALIAS abs={} can={}",abs,can);
+                if (LOG.isDebugEnabled())
+                    LOG.debug("ALIAS abs={} can={}",abs,can);
 
                 URI alias=new File(can).toURI();
                 // Have to encode the path as File.toURI does not!
@@ -183,6 +184,7 @@ public class FileResource extends Resource
     public Resource addPath(String path)
         throws IOException,MalformedURLException
     {
+        assertValidPath(path);
         path = org.eclipse.jetty.util.URIUtil.canonicalPath(path);
 
         if (path==null)
@@ -208,13 +210,21 @@ public class FileResource extends Resource
         }
         catch(final URISyntaxException e)
         {
-            throw new MalformedURLException(){{initCause(e);}};
+            throw new InvalidPathException(path, e.getMessage());
         }
 
         return new FileResource(uri);
     }
-   
-    
+
+    private void assertValidPath(String path)
+    {
+        int idx = StringUtil.indexOfControlChars(path);
+        if (idx >= 0)
+        {
+            throw new InvalidPathException(path, "Invalid Character at index " + idx);
+        }
+    }
+
     /* ------------------------------------------------------------ */
     @Override
     public URI getAlias()