xlawrence    2005/06/21 16:12:12 CEST

  Modified files:
    core/src/java/org/jahia/urls ContentServletURL.java 
  Log:
  Added check to prevent a NumberFormatException breaking all the process
  
  Revision  Changes    Path
  1.3       +54 -49    jahia/core/src/java/org/jahia/urls/ContentServletURL.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/urls/ContentServletURL.java.diff?r1=1.2&r2=1.3&f=h
  
  
  
  Index: ContentServletURL.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/urls/ContentServletURL.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ContentServletURL.java    27 Sep 2004 17:43:22 -0000      1.2
  +++ ContentServletURL.java    21 Jun 2005 14:12:12 -0000      1.3
  @@ -18,25 +18,25 @@
    */
   
   public class ContentServletURL extends ServletURL {
  -
  +    
       private static org.apache.log4j.Logger logger =
  -            org.apache.log4j.Logger.getLogger (ContentServletURL.class);
  -
  +            org.apache.log4j.Logger.getLogger(ContentServletURL.class);
  +    
       InsertionSortedMap pathInfoParameters = new InsertionSortedMap();
  -
  -    public ContentServletURL (HttpServletRequest request)
  -        throws MalformedURLException {
  +    
  +    public ContentServletURL(HttpServletRequest request)
  +    throws MalformedURLException {
           super(request);
       }
  -
  -    public ContentServletURL (HttpServletRequest request, String url, 
boolean ignoringAuthorityInTest) throws MalformedURLException {
  +    
  +    public ContentServletURL(HttpServletRequest request, String url, boolean 
ignoringAuthorityInTest) throws MalformedURLException {
           super();
           if (!ContentServletURL.isContentServletURL(request, url,
  -            ignoringAuthorityInTest)) {
  +                ignoringAuthorityInTest)) {
               throw new MalformedURLException("URL " + url +
  -                " is not a valid content servlet URL");
  +                    " is not a valid content servlet URL");
           }
  -
  +        
           /** @todo this code is not optimized and very similar to the
            * isContentServletURL method ! Find a cleaner way to do this !
            */
  @@ -65,7 +65,7 @@
           // in relative mode or in fully qualified mode.
           String targetPath = targetURL.getPath();
           String targetServletPath = targetPath.substring(requestURL.
  -            getContextPath().length());
  +                getContextPath().length());
           int queryPos = targetServletPath.indexOf("?");
           int fragmentPos = targetServletPath.indexOf("#");
           String targetQueryString = null;
  @@ -73,7 +73,7 @@
           String targetPathInfo;
           if (queryPos > 0) {
               targetPathInfo = targetServletPath.substring(requestURL.
  -                getServletPath().length(), queryPos);
  +                    getServletPath().length(), queryPos);
               if (fragmentPos > 0) {
                   targetQueryString = targetServletPath.substring(queryPos+1, 
fragmentPos);
                   targetFragmentString = 
targetServletPath.substring(fragmentPos+1);
  @@ -82,29 +82,34 @@
               }
           } else if (fragmentPos > 0) {
               targetPathInfo = targetServletPath.substring(requestURL.
  -                getServletPath().length(), fragmentPos);
  +                    getServletPath().length(), fragmentPos);
               targetFragmentString = 
targetServletPath.substring(fragmentPos+1);
           } else {
               targetPathInfo = targetServletPath.substring(requestURL.
  -                getServletPath().length());
  +                    getServletPath().length());
           }
           setPathInfo(targetPathInfo);
           setQueryString(targetQueryString);
           setFragmentString(targetFragmentString);
       }
  -
  -    static public boolean isContentServletURL (HttpServletRequest request,
  -                                               String url, boolean 
ignoringAuthorityInTest)
  -        throws MalformedURLException {
  -        ContentServletURL requestURL = new ContentServletURL(request);
  -        String useURL = url;
  -        URI targetURL = new URI(useURL);
  +    
  +    static public boolean isContentServletURL(HttpServletRequest request,
  +            final String url, boolean ignoringAuthorityInTest)
  +            throws MalformedURLException {
  +        final ContentServletURL requestURL = new ContentServletURL(request);
  +        final URI targetURL;
  +        try {
  +            targetURL = new URI(url);
  +        } catch (Exception e) {
  +            logger.warn("URI '"+ url + "' is not valid");
  +            return false;
  +        }
           // now let's compare with the request URL to see if they match. The
           // detail of this comparison depends on weather we are comparing
           // in relative mode or in fully qualified mode.
           if ((!targetURL.isURIStartingAtPath()) &&
  -            (!targetURL.isRelative()) &&
  -            (!ignoringAuthorityInTest)) {
  +                (!targetURL.isRelative()) &&
  +                (!ignoringAuthorityInTest)) {
               if (!requestURL.getScheme().equals(targetURL.getScheme())) {
                   return false;
               }
  @@ -116,15 +121,15 @@
               }
           }
           if (!targetURL.isRelative()) {
  -        String targetPath = targetURL.getPath();
  -        if (!targetPath.startsWith(requestURL.getContextPath())) {
  -            return false;
  -        }
  -        String targetServletPath = targetPath.substring(requestURL.
  -            getContextPath().length());
  -        if (!targetServletPath.startsWith(requestURL.getServletPath())) {
  -            return false;
  -        }
  +            String targetPath = targetURL.getPath();
  +            if (!targetPath.startsWith(requestURL.getContextPath())) {
  +                return false;
  +            }
  +            String targetServletPath = targetPath.substring(requestURL.
  +                    getContextPath().length());
  +            if (!targetServletPath.startsWith(requestURL.getServletPath())) {
  +                return false;
  +            }
           }
           // if we got this far this means we have successfully matched both 
the
           // context and the servlet path.
  @@ -135,15 +140,15 @@
            */
           return true;
       }
  -
  +    
       public String getPathInfoParameter(String name) {
           return (String) pathInfoParameters.get(name);
       }
  -
  +    
       public String setPathInfoParameter(String name, String value) {
           return (String) pathInfoParameters.put(name, value);
       }
  -
  +    
       public String getPathInfo() {
           if (pathInfoParameters.size() == 0) {
               return null;
  @@ -158,26 +163,26 @@
               result.append(curEntry.getValue());
           }
           return result.toString();
  -
  +        
       }
  -
  +    
       public void setPathInfo(String pathInfo) {
           super.setPathInfo(pathInfo);
           parsePathInfoParameters(pathInfo);
       }
  -
  -    private void parsePathInfoParameters (String pathInfo) {
  +    
  +    private void parsePathInfoParameters(String pathInfo) {
           // Parse the PathInfo and build a custom parameter map
  -
  +        
           if (pathInfo != null) {
  -
  +            
               if (pathInfo.lastIndexOf(";jsessionid=") != -1) {
                   // let's remove the session ID from the parameters if it was 
attached.
                   int sessionIDPos = pathInfo.lastIndexOf(";jsessionid=");
                   pathInfo = pathInfo.substring(0, sessionIDPos);
                   logger.debug("Removed session ID marker from end of path 
info");
               }
  -
  +            
               if (pathInfo.lastIndexOf(".") != -1) {
                   // let's remove false static ending.
                   int lastSlash = pathInfo.lastIndexOf("/");
  @@ -185,23 +190,23 @@
                       String fakeStaticName = pathInfo.substring(lastSlash + 
1);
                       pathInfo = pathInfo.substring(0, lastSlash);
                       logger.debug("Removed fake static ending. pathInfo=[" +
  -                                 pathInfo + "] fakeEnding=[" +
  -                                 fakeStaticName + "]");
  +                            pathInfo + "] fakeEnding=[" +
  +                            fakeStaticName + "]");
                   }
               }
  -
  +            
               try {
                   StringTokenizer st = new StringTokenizer(pathInfo, "/");
  -
  +                
                   while (st.hasMoreTokens()) {
                       String token = st.nextToken();
                       pathInfoParameters.put(token, st.nextToken());
                   }
  -
  +                
               } catch (NoSuchElementException nee) {
                   // stop parsing token
               }
           }
       }
  -
  +    
   }
  \ No newline at end of file
  

Reply via email to