From: <wpb...@us...> - 2011-09-10 09:10:34
|
Revision: 2471 http://geshi.svn.sourceforge.net/geshi/?rev=2471&view=rev Author: wpblatchley Date: 2011-09-10 09:10:28 +0000 (Sat, 10 Sep 2011) Log Message: ----------- Fixes a subtle bug in _codecontexthighlight whereby if there are two keywords, one of which is the same as the other but longer (e.g. "OF" and "OFF"), and the longer one exists in a later keyword group than the shorter, GeSHi fails to highlight the longer keyword. The existing logic was only updating $next_keyword if a new keyword was matched before the current match, and not taking into account the length of the current match, and the possibility that a later match at the same position could be longer. Modified Paths: -------------- trunk/geshi-src/geshi/classes/class.geshicodecontext.php Modified: trunk/geshi-src/geshi/classes/class.geshicodecontext.php =================================================================== --- trunk/geshi-src/geshi/classes/class.geshicodecontext.php 2011-09-10 08:56:20 UTC (rev 2470) +++ trunk/geshi-src/geshi/classes/class.geshicodecontext.php 2011-09-10 09:10:28 UTC (rev 2471) @@ -358,6 +358,7 @@ $next_keyword_pos = -1; $next_keyword_group = ''; $next_keyword = ''; + $next_keyword_len = 0; // For each character for ($i = 0; $i < $length; $i++) { if (isset($regex_replacements[$i])) { @@ -421,11 +422,14 @@ geshi_dbg(" keywordgroup $group_key is never again matched"); continue; } - if ($match_i !== false && $match_i < $next_keyword_pos) { + $keyword_len = strlen($keyword); + if (($match_i !== false && $match_i < $next_keyword_pos) || + ($match_i == $next_keyword_pos && $keyword_len > $next_keyword_len)) { $next_keyword_pos = $match_i; $next_keyword_group = $group_key; $next_keyword = $keyword; - geshi_dbg(" next keyword: $next_keyword (group $group_key) at pos $match_i"); + $next_keyword_len = $keyword_len; + geshi_dbg(" next keyword: $next_keyword (group $group_key) at pos $match_i (unless longer match is found)"); if ($match_i === $i) { break; } @@ -447,8 +451,9 @@ var_dump($i, $next_keyword_pos); } $i += strlen($next_keyword) - 1; - geshi_dbg("strlen of keyword is " . strlen($next_keyword) . " (pos is $i)"); + geshi_dbg("strlen of keyword is " . $next_keyword_len . " (pos is $i)"); $next_keyword_pos = false; + $next_keyword_len = 0; } } if (!$matched_keyword) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |