You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2001/12/10 05:47:03 UTC

DO NOT REPLY [Bug 5333] - getRealPath("") without final \

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5333>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5333

getRealPath("") without final \

craig.mcclanahan@sun.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



------- Additional Comments From craig.mcclanahan@sun.com  2001-12-09 20:47 -------
The Javadocs for getRealPath say this:

    Returns a String containing the real path for a given virtual path. For 
    example, the path "/index.html" returns the absolute file
     path on the server's filesystem would be served by a request for 
    "http://host/contextPath/index.html", where contextPath is the
     context path of this ServletContext.. 

For a directory, a path that does not end in a "/" character is valid on *all* 
operating system platforms, while a path that ends in "/" is only valid on some 
platforms.  However, the important issues is that both are valid on the majority 
of platforms.  Therefore, any application that makes any assumptions about 
whether or not there is a trailing slash are guaranteed to be non-portable, and 
should be corrected.

The standard approach to this (if your application logic requires a trailing 
"/") is to do something like this:

    String realPath = getServletContext.getRealPath(path);
    if ((realPath != null) && !realPath.endsWith("/"))
        realPath += "/";

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>