diff --git a/_test/tests/inc/difference_engine.test.php b/_test/tests/inc/difference_engine.test.php new file mode 100644 index 0000000000000000000000000000000000000000..cd0c9c0317a4e03fe2bc80d8a1ae8494544d52e2 --- /dev/null +++ b/_test/tests/inc/difference_engine.test.php @@ -0,0 +1,85 @@ +<?php + +require_once DOKU_INC.'inc/DifferenceEngine.php'; + +/** + * Class difference_engine_test + */ +class difference_engine_test extends DokuWikiTest { + public $x = "zzz\n\naaa\n\nbbb\n\nccc\n\nddd\n\nddd\n\nddd\n\neee\n\nfff"; + public $y = "ddd\n\naaa\n\nbbb\n\nbbb\n\nccc\n\nccc\n\neee"; + + function test_render_table(){ + $diff = new Diff(explode("\n", $this->x), explode("\n", $this->y)); + $diffformatter = new TableDiffFormatter(); + $actual = $diffformatter->format($diff); + $expected = '<tr><td class="diff-blockheader" colspan="2">Line 1:</td> +<td class="diff-blockheader" colspan="2">Line 1:</td> +</tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"><strong class="diff-mark">zzz</strong></td><td class="diff-lineheader">+</td><td class="diff-addedline"><strong class="diff-mark">ddd</strong></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">aaa</td><td class="diff-lineheader"> </td><td class="diff-context">aaa</td></tr> +<tr><td colspan="2"> </td><td class="diff-lineheader">+</td><td class="diff-addedline"></td></tr> +<tr><td colspan="2"> </td><td class="diff-lineheader">+</td><td class="diff-addedline">bbb</td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">bbb</td><td class="diff-lineheader"> </td><td class="diff-context">bbb</td></tr> +<tr><td class="diff-blockheader" colspan="2">Line 7:</td> +<td class="diff-blockheader" colspan="2">Line 9:</td> +</tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">ccc</td><td class="diff-lineheader"> </td><td class="diff-context">ccc</td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"><strong class="diff-mark">ddd </strong></td><td class="diff-lineheader">+</td><td class="diff-addedline"><strong class="diff-mark">ccc</strong></td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"><strong class="diff-mark"> </strong></td><td class="diff-lineheader">+</td><td class="diff-addedline"></td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"><strong class="diff-mark">ddd </strong></td><td class="diff-lineheader">+</td><td class="diff-addedline"></td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"><strong class="diff-mark"> </strong></td><td class="diff-lineheader">+</td><td class="diff-addedline"></td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"><strong class="diff-mark">ddd</strong></td><td class="diff-lineheader">+</td><td class="diff-addedline"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">eee</td><td class="diff-lineheader"> </td><td class="diff-context">eee</td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline"></td><td colspan="2"> </td></tr> +<tr><td class="diff-lineheader">-</td><td class="diff-deletedline">fff</td><td colspan="2"> </td></tr> +'; + $this->assertEquals($expected, $actual); + } + + function test_render_inline(){ + $diff = new Diff(explode("\n", $this->x), explode("\n", $this->y)); + $diffformatter = new InlineDiffFormatter(); + $actual = $diffformatter->format($diff); + $expected = '<tr><td colspan="2" class="diff-blockheader">@@ Line -1,5 +1,7 @@ <span class="diff-deletedline"><del>removed</del></span> <span class="diff-addedline">created</span></td></tr> + +<tr><td class="diff-lineheader"> </td><td><span class="diff-deletedline"><del>zzz</del></span><span class="diff-addedline">ddd</span></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">aaa</td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-addedline"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-addedline">bbb</td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">bbb</td></tr> +<tr><td colspan="2" class="diff-blockheader">@@ Line -7,11 +9,5 @@ <span class="diff-deletedline"><del>removed</del></span> <span class="diff-addedline">created</span></td></tr> + +<tr><td class="diff-lineheader"> </td><td class="diff-context">ccc</td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td><span class="diff-deletedline"><del>ddd </del></span></td></tr> +<tr><td class="diff-lineheader"> </td><td><span class="diff-deletedline"><del> </del></span></td></tr> +<tr><td class="diff-lineheader"> </td><td><span class="diff-deletedline"><del>ddd </del></span></td></tr> +<tr><td class="diff-lineheader"> </td><td><span class="diff-deletedline"><del> </del></span></td></tr> +<tr><td class="diff-lineheader"> </td><td><span class="diff-deletedline"><del>ddd</del></span><span class="diff-addedline">ccc</span></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context"></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-context">eee</td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-deletedline"><del></del></td></tr> +<tr><td class="diff-lineheader"> </td><td class="diff-deletedline"><del>fff</del></td></tr> +'; + $this->assertEquals($expected, $actual); + } + + function test_engine_diag(){ + // initialize + $eng = new _DiffEngine; + $eng->diff(explode("\n", $this->x), explode("\n", $this->y)); + // check + $this->assertEquals( + array(9, array(array(0,0),array(1,2),array(3,4),array(4,5),array(5,7),array(6,9),array(7,10),array(9,12),array(15,13))), + $eng->_diag(0, 15, 0, 13, 8) + ); + } +} +//Setup VIM: ex: et ts=4 : diff --git a/inc/DifferenceEngine.php b/inc/DifferenceEngine.php index 37b55e10daa8939b1be92102f6e97ceaccc41e5a..70877a4f2dee180a16e9a636175a0a958b6b8675 100644 --- a/inc/DifferenceEngine.php +++ b/inc/DifferenceEngine.php @@ -270,16 +270,9 @@ class _DiffEngine { if (empty($ymatches[$line])) continue; $matches = $ymatches[$line]; - reset($matches); - while (list ($junk, $y) = each($matches)) - if (empty($this->in_seq[$y])) { - $k = $this->_lcs_pos($y); - USE_ASSERTS && assert($k > 0); - $ymids[$k] = $ymids[$k-1]; - break; - } - while (list ($junk, $y) = each($matches)) { - if ($y > $this->seq[$k-1]) { + $switch = false; + foreach ($matches as $y) { + if ($switch && $y > $this->seq[$k-1]) { USE_ASSERTS && assert($y < $this->seq[$k]); // Optimization: this is a common case: // next match is just replacing previous match. @@ -291,6 +284,7 @@ class _DiffEngine { $k = $this->_lcs_pos($y); USE_ASSERTS && assert($k > 0); $ymids[$k] = $ymids[$k-1]; + $switch = true; } } } @@ -414,7 +408,7 @@ class _DiffEngine { $i = 0; $j = 0; - USE_ASSERTS && assert('count($lines) == count($changed)'); + USE_ASSERTS && assert(count($lines) == count($changed)); $len = count($lines); $other_len = count($other_changed); @@ -434,7 +428,7 @@ class _DiffEngine { $j++; while ($i < $len && ! $changed[$i]) { - USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]'); + USE_ASSERTS && assert($j < $other_len && ! $other_changed[$j]); $i++; $j++; while ($j < $other_len && $other_changed[$j]) @@ -467,10 +461,10 @@ class _DiffEngine { $changed[--$i] = false; while ($start > 0 && $changed[$start - 1]) $start--; - USE_ASSERTS && assert('$j > 0'); + USE_ASSERTS && assert($j > 0); while ($other_changed[--$j]) continue; - USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]'); + USE_ASSERTS && assert($j >= 0 && !$other_changed[$j]); } /* @@ -493,7 +487,7 @@ class _DiffEngine { while ($i < $len && $changed[$i]) $i++; - USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]'); + USE_ASSERTS && assert($j < $other_len && ! $other_changed[$j]); $j++; if ($j < $other_len && $other_changed[$j]) { $corresponding = $i; @@ -510,10 +504,10 @@ class _DiffEngine { while ($corresponding < $i) { $changed[--$start] = 1; $changed[--$i] = 0; - USE_ASSERTS && assert('$j > 0'); + USE_ASSERTS && assert($j > 0); while ($other_changed[--$j]) continue; - USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]'); + USE_ASSERTS && assert($j >= 0 && !$other_changed[$j]); } } } @@ -876,10 +870,10 @@ class DiffFormatter { /** * Escape string - * + * * Override this method within other formatters if escaping required. * Base class requires $str to be returned WITHOUT escaping. - * + * * @param $str string Text string to escape * @return string The escaped string. */ diff --git a/inc/JpegMeta.php b/inc/JpegMeta.php index d667ce303d88dd53fb429d6edc3f28412a6e90f0..94c276cfa7af94d0c6dbbd05567c17bc18921fb4 100644 --- a/inc/JpegMeta.php +++ b/inc/JpegMeta.php @@ -2522,13 +2522,13 @@ class JpegMeta { $pos = 14; reset($this->_info['adobe']['raw']); - while (list($key) = each($this->_info['adobe']['raw'])) { + foreach ($this->_info['adobe']['raw'] as $value){ $pos = $this->_write8BIM( $data, $pos, - $this->_info['adobe']['raw'][$key]['type'], - $this->_info['adobe']['raw'][$key]['header'], - $this->_info['adobe']['raw'][$key]['data'] ); + $value['type'], + $value['header'], + $value['data'] ); } } diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index 9dece24279cc740805339991b9ed8d701ee841fa..52f9ba50dc073fd8185b3bc84193b364554f8de5 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -184,10 +184,10 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { $info = array(); $info['user'] = $user; $this->_debug('LDAP user to find: '.htmlspecialchars($info['user']), 0, __LINE__, __FILE__); - + $info['server'] = $this->getConf('server'); $this->_debug('LDAP Server: '.htmlspecialchars($info['server']), 0, __LINE__, __FILE__); - + //get info for given user $base = $this->_makeFilter($this->getConf('usertree'), $info); @@ -198,20 +198,20 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { } $this->_debug('LDAP Filter: '.htmlspecialchars($filter), 0, __LINE__, __FILE__); - + $this->_debug('LDAP user search: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); $this->_debug('LDAP search at: '.htmlspecialchars($base.' '.$filter), 0, __LINE__, __FILE__); $sr = $this->_ldapsearch($this->con, $base, $filter, $this->getConf('userscope')); - + $result = @ldap_get_entries($this->con, $sr); // if result is not an array if(!is_array($result)) { // no objects found $this->_debug('LDAP search returned non-array result: '.htmlspecialchars(print($result)), -1, __LINE__, __FILE__); - return false; + return false; } - + // Don't accept more or less than one response if ($result['count'] != 1) { $this->_debug('LDAP search returned '.htmlspecialchars($result['count']).' results while it should return 1!', -1, __LINE__, __FILE__); @@ -220,10 +220,10 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { //} return false; } - - + + $this->_debug('LDAP search found single result !', 0, __LINE__, __FILE__); - + $user_result = $result[0]; ldap_free_result($sr); @@ -239,7 +239,9 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { foreach($this->getConf('mapping') as $localkey => $key) { if(is_array($key)) { // use regexp to clean up user_result - list($key, $regexp) = each($key); + // $key = array($key=>$regexp), only handles the first key-value + $regexp = current($key); + $key = key($key); if($user_result[$key]) foreach($user_result[$key] as $grpkey => $grp) { if($grpkey !== 'count' && preg_match($regexp, $grp, $match)) { if($localkey == 'grps') { diff --git a/lib/plugins/config/admin.php b/lib/plugins/config/admin.php index 262ff46d9b76201690f791275512481cd70b545d..76ecae24ccc86201f256be36c4153e5747d1ef3a 100644 --- a/lib/plugins/config/admin.php +++ b/lib/plugins/config/admin.php @@ -60,7 +60,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { $this->_input = $INPUT->arr('config'); - while (list($key) = each($this->_config->setting)) { + foreach ($this->_config->setting as $key => $value){ $input = isset($this->_input[$key]) ? $this->_input[$key] : null; if ($this->_config->setting[$key]->update($input)) { $this->_changed = true;