bruno       2003/06/10 02:40:15

  Modified:    sourceresolve/src/java/org/apache/excalibur/source
                        SourceUtil.java
  Log:
  Avoid a stackoverflow exception with really long query strings.
  
  Revision  Changes    Path
  1.10      +24 -4     
avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java
  
  Index: SourceUtil.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/SourceUtil.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SourceUtil.java   7 Jun 2003 20:59:40 -0000       1.9
  +++ SourceUtil.java   10 Jun 2003 09:40:15 -0000      1.10
  @@ -554,12 +554,32 @@
           if (url1 == null)
               return url2;
   
  +        // do this before parsing using the regexp as a performance optimalisation
  +        if (getScheme(url2) != null)
  +            return url2;
  +
  +        // regexp can be slow (and give stack overflows) with large query strings, 
so cut them of here
  +        String query1 = null, query2 = null;
  +        int queryPos = url1.indexOf('?');
  +        if (queryPos != -1)
  +        {
  +            query1 = url1.substring(queryPos + 1);
  +            url1 = url1.substring(0, queryPos);
  +        }
  +        queryPos = url2.indexOf('?');
  +        if (queryPos != -1)
  +        {
  +            query2 = url2.substring(queryPos + 1);
  +            url2 = url2.substring(0, queryPos);
  +        }
  +
           // parse the urls into parts
           // if the second url contains a scheme, it is not relative so return it 
right away (part 3 of the algorithm)
  -        String[] url2Parts = parseUrl(url2);
  -        if (url2Parts[SCHEME] != null)
  -            return url2;
           String[] url1Parts = parseUrl(url1);
  +        String[] url2Parts = parseUrl(url2);
  +
  +        url1Parts[QUERY] = query1;
  +        url2Parts[QUERY] = query2;
   
           if (treatAuthorityAsBelongingToPath)
               return absolutizeWithoutAuthority(url1Parts, url2Parts);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to