You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2003/04/15 17:58:19 UTC

cvs commit: xml-xerces/c/src/xercesc/util XMLUri.cpp

peiyongz    2003/04/15 08:58:19

  Modified:    c/src/xercesc/util XMLUri.cpp
  Log:
  Bug#17096 XMLUri relative path calculation badly broken
  patch from berin@ozemail.com.au (Berin Lautenbach)
  
  Revision  Changes    Path
  1.10      +25 -12    xml-xerces/c/src/xercesc/util/XMLUri.cpp
  
  Index: XMLUri.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLUri.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLUri.cpp	6 Dec 2002 16:54:58 -0000	1.9
  +++ XMLUri.cpp	15 Apr 2003 15:58:19 -0000	1.10
  @@ -200,9 +200,9 @@
       chForwardSlash, chNull
   };
   
  -static const XMLCh DOT_SLASH[] =
  +static const XMLCh SLASH_DOT_SLASH[] =
   {
  -    chPeriod, chForwardSlash, chNull
  +    chForwardSlash, chPeriod, chForwardSlash, chNull
   };
   
   static const XMLCh SLASH_DOT[] =
  @@ -557,7 +557,7 @@
   
           // 6c - remove all "./" where "." is a complete path segment
           index = -1;
  -        while ((index = XMLString::patternMatch(path, DOT_SLASH)) != -1)
  +        while ((index = XMLString::patternMatch(path, SLASH_DOT_SLASH)) != -1)
           {
               XMLString::subString(tmp1, path, 0, index);
               XMLString::subString(tmp2, path, index+2, XMLString::stringLen(path));
  @@ -575,16 +575,26 @@
   
           // 6e - remove all "<segment>/../" where "<segment>" is a complete
           // path segment not equal to ".."
  -        index = 1;
  +        index = -1;
           int segIndex = -1;
  +		int offset = 1;
   
  -        while ((index = XMLString::patternMatch(&(path[1]), SLASH_DOTDOT_SLASH)) != -1)
  +        while ((index = XMLString::patternMatch(&(path[offset]), SLASH_DOTDOT_SLASH)) != -1)
           {
  -            segIndex = XMLString::lastIndexOf(&(path[index-1]), chForwardSlash);
  +			// Undo offset
  +			index += offset;
  +
  +			// Find start of <segment> within substring ending at found point.
  +			XMLString::subString(tmp1, path, 0, index-1);
  +			segIndex = XMLString::lastIndexOf(tmp1, chForwardSlash);
  +
  +			// Ensure <segment> exists and != ".."
               if (segIndex != -1                &&
                   (path[segIndex+1] != chPeriod ||
  -                 path[index] != chPeriod))
  +                 path[segIndex+2] != chPeriod ||
  +				 segIndex + 3 != index))
               {
  +
                   XMLString::subString(tmp1, path, 0, segIndex);
                   XMLString::subString(tmp2, path, index+3, XMLString::stringLen(path));
   
  @@ -592,11 +602,11 @@
                   XMLString::catString(path, tmp1);
                   XMLString::catString(path, tmp2);
   
  -                index = segIndex;
  +                offset = (segIndex == 0 ? 1 : segIndex);
               }
               else
               {
  -                index += 4;
  +                offset += 4;
               }
           }// while
   
  @@ -604,12 +614,15 @@
           // complete path segment
           if (XMLString::endsWith(path, SLASH_DOTDOT))
           {
  +			// Find start of <segment> within substring ending at found point.
               index = XMLString::stringLen(path) - 3;
  -            segIndex = XMLString::lastIndexOf(&(path[index-1]), chForwardSlash);
  +			XMLString::subString(tmp1, path, 0, index-1);
  +			segIndex = XMLString::lastIndexOf(tmp1, chForwardSlash);
   
               if (segIndex != -1                &&
                   (path[segIndex+1] != chPeriod ||
  -                 path[index] != chPeriod))
  +                 path[segIndex+2] != chPeriod ||
  +				 segIndex + 3 != index))
               {
                   path[segIndex+1] = chNull;
               }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org