CVS update: /cowiki/includes/cowiki/class/parse/

[email protected] 26 Jul 2005 16:53:12 -0000
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
User: cmarble 
Date: 2005/07/26 09:53:12

Modified:
   cowiki/includes/cowiki/class/parse/class.WikiParser.php

Log:
 These lines :
 
     <?xml version="1.0" standalone="yes"?>
     <users>
             <user username="TEST" passwordHash="43DA2DD96277F66BC1813670241B65CA" id_entity="5893434" />
     </users>
 
 from David Ramalho were causing a stalled-loop within the greedy tag handler (see unit tests). A loop is now capped with an error message, as for other similar problems. The parser will only find "&gt;" strange within an xml tag, which it is [sic]. Formerly, a regex involving any ampersand had caused the parser to stall. 
 
 Emphatically, the parser is not at this execution point an xml parser, but handles passing over other non-<code> tags by ignoring their content and noting their closing bracket. Similar bugs may well arise. They will be corrected at that time.
 
 Regards,
 
 Archie

File Changes:

Directory: /cowiki/includes/cowiki/class/parse/
===============================================

File [changed]: class.WikiParser.php
Url: http://cowiki.tigris.org/source/browse/cowiki/includes/cowiki/class/parse/class.WikiParser.php?r1=1.56&r2=1.57
Delta lines:  +17 -6
--------------------
--- class.WikiParser.php	26 Jul 2005 16:06:41 -0000	1.56
+++ class.WikiParser.php	26 Jul 2005 16:53:10 -0000	1.57
@@ -2,7 +2,7 @@
 
 /**
  *
- * $Id: class.WikiParser.php,v 1.56 2005/07/26 16:06:41 cmarble Exp $
+ * $Id: class.WikiParser.php,v 1.57 2005/07/26 16:53:10 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -21,7 +21,7 @@
  * @author      Daniel T. Gorski, <[email protected]>
  * @copyright   (C) Daniel T. Gorski, {@link http://www.develnet.org}
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.56 $
+ * @version     $Revision: 1.57 $
  *
  */
 
@@ -379,17 +379,18 @@
             // closing tag or eoln anywhere on a line
             } else if (preg_match( '=^&lt;(pre|code|posting|q|rem|noop)&gt;=i',
                                     $sStr, $aMatch ) ) {
-              if($debug){echo "1\n";}
+              if($debug){echo "1 ".$aMatch[1]."\n";}
                 $sStr = substr( $sStr, strlen($aMatch[0]) );
                 $curLine = $this->iRow;
                 $curLen = strlen( $sStr );
                 $sContent = '';
+                $lastStr = $sStr;
                 while( !preg_match( '=^&lt;/'.$aMatch[1].'&gt;=is', 
                                                 $sStr, $aMatches ) ) {
-                    if(preg_match( '#^&lt;[^&]*&gt;#is', $sStr, $aMatches )){
+                    if(preg_match( '#^&lt;([^&]|(\&(?!gt;)))*&gt;#is', $sStr, $aMatches )){
                         $sContent .= $aMatches[0];
                         $sStr = substr( $sStr, strlen( $aMatches[0] ) );
-                    } else if(preg_match( '=^([^&]|(\&(?!l)))*=is', $sStr, $aMatches )){
+                    } else if(preg_match( '=^([^&]|(\&(?!lt;)))*=is', $sStr, $aMatches )){
                         $sContent .= $aMatches[0];
                         $sStr = substr( $sStr, strlen( $aMatches[0] ) );
                     }
@@ -402,6 +403,16 @@
                             $sStr = substr( $sStr, strlen( $sStr )-$curLen );
                             break;
                         }
+                    } else {
+                        if ( $debug ) { echo "greedy ".$sStr."\n"; }
+                    }
+                    if ( $lastStr == $sStr ) {
+                        $msg = "Parse failed whilst ".$aMatch[1]."\n";
+                        $sContent .= $msg;
+                        if ( $debug) { echo $msg; }
+                        break;
+                    } else {
+                        $lastStr = $sStr;
                     }
                 }
                 if ( $this->iRow < sizeof($this->aRows) ) {
@@ -652,7 +663,7 @@
             if( $lastStr == $sStr ) {
                 $msg = "Parse failed before ".$sStr."\n";
                 $sRet .= $msg;
-                echo $msg;              
+                if ($debug) { echo $msg; }
                 break;
             } else {
                 $lastStr = $sStr;