cvs: pear /Net_LDAP2 LDAP2.php /Net_LDAP2/LDAP2 LDIF.php /Net_LDAP2/tests Net_LDAP2_LDIFTest.php
| From: | Benedikt Hallinger | Date: | Thu, 30 Apr 2009 09:11:23 +0000 |
| Subject: | cvs: pear /Net_LDAP2 LDAP2.php /Net_LDAP2/LDAP2 LDIF.php /Net_LDAP2/tests Net_LDAP2_LDIFTest.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-56016@lists.php.net to get a copy of this message | ||
beni Thu Apr 30 09:11:23 2009 UTC
Modified files:
/pear/Net_LDAP2 LDAP2.php
/pear/Net_LDAP2/LDAP2 LDIF.php
/pear/Net_LDAP2/tests Net_LDAP2_LDIFTest.php
Log:
* Bugfix in encoding of LDIF written entries if init char of value is illegal and must be encoded
* Adjustet test case
* New test case for modified behavior in 2.0.0RC5 (write_version)
http://cvs.php.net/viewvc.cgi/pear/Net_LDAP2/LDAP2.php?r1=1.16&r2=1.17&diff_format=u
Index: pear/Net_LDAP2/LDAP2.php
diff -u pear/Net_LDAP2/LDAP2.php:1.16 pear/Net_LDAP2/LDAP2.php:1.17
--- pear/Net_LDAP2/LDAP2.php:1.16 Thu Apr 30 07:23:26 2009
+++ pear/Net_LDAP2/LDAP2.php Thu Apr 30 09:11:23 2009
@@ -13,8 +13,8 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2003-2007 Tarjej Huse, Jan Wagner, Del Elson, Benedikt Hallinger
* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @version CVS: $Id: LDAP2.php,v 1.16 2009/04/30 07:23:26 beni Exp $
-* @link http://pear.php.net/package/Net_LDAP22/
+* @version CVS: $Id: LDAP2.php,v 1.17 2009/04/30 09:11:23 beni Exp $
+* @link http://pear.php.net/package/Net_LDAP2/
*/
/**
@@ -50,8 +50,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2003-2007 Tarjej Huse, Jan Wagner, Del Elson, Benedikt Hallinger
* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @version CVS: $Id: LDAP2.php,v 1.16 2009/04/30 07:23:26 beni Exp $
-* @link http://pear.php.net/package/Net_LDAP22/
+* @link http://pear.php.net/package/Net_LDAP2/
*/
class Net_LDAP2 extends PEAR
{
@@ -366,7 +365,6 @@
*/
protected function performConnect()
{
-
// Return true if we are already connected.
if ($this->_link !== false) {
return true;
@@ -411,7 +409,7 @@
$this->_config['host'] = $host;
// Attempt a connection.
- $this->_link = @ldapperformConnect($host, $this->_config['port']);
+ $this->_link = @ldap_connect($host, $this->_config['port']);
if (false === $this->_link) {
$current_error = PEAR::raiseError('Could not connect to ' .
$host . ':' . $this->_config['port']);
http://cvs.php.net/viewvc.cgi/pear/Net_LDAP2/LDAP2/LDIF.php?r1=1.8&r2=1.9&diff_format=u
Index: pear/Net_LDAP2/LDAP2/LDIF.php
diff -u pear/Net_LDAP2/LDAP2/LDIF.php:1.8 pear/Net_LDAP2/LDAP2/LDIF.php:1.9
--- pear/Net_LDAP2/LDAP2/LDIF.php:1.8 Thu Apr 30 07:58:35 2009
+++ pear/Net_LDAP2/LDAP2/LDIF.php Thu Apr 30 09:11:23 2009
@@ -10,7 +10,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2009 Benedikt Hallinger
* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @version CVS: $Id: LDIF.php,v 1.8 2009/04/30 07:58:35 beni Exp $
+* @version CVS: $Id: LDIF.php,v 1.9 2009/04/30 09:11:23 beni Exp $
* @link http://pear.php.net/package/Net_LDAP2/
*/
@@ -747,14 +747,14 @@
// Test for illegal init char
$init_ord = ord(substr($attr_value, 0, 1));
- if ($init_ord >= 127 || in_array($init_ord, $unsafe_init)) {
+ if ($init_ord > 127 || in_array($init_ord, $unsafe_init)) {
$base64 = true;
}
// Test for illegal content char
for ($i = 0; $i < strlen($attr_value); $i++) {
- $char = substr($attr_value, $i, 1);
- if (ord($char) >= 127 || in_array($char, $unsafe)) {
+ $char_ord = ord(substr($attr_value, $i, 1));
+ if ($char_ord > 127 || in_array($char_ord, $unsafe)) {
$base64 = true;
}
}
http://cvs.php.net/viewvc.cgi/pear/Net_LDAP2/tests/Net_LDAP2_LDIFTest.php?r1=1.3&r2=1.4&diff_format=u
Index: pear/Net_LDAP2/tests/Net_LDAP2_LDIFTest.php
diff -u pear/Net_LDAP2/tests/Net_LDAP2_LDIFTest.php:1.3
pear/Net_LDAP2/tests/Net_LDAP2_LDIFTest.php:1.4
--- pear/Net_LDAP2/tests/Net_LDAP2_LDIFTest.php:1.3 Thu May 8 10:08:16 2008
+++ pear/Net_LDAP2/tests/Net_LDAP2_LDIFTest.php Thu Apr 30 09:11:23 2009
@@ -31,6 +31,7 @@
'wrap' => 50,
'change' => 0,
'sort' => 0,
+ 'version' => 1 // mimic pre 2.0.0RC5 behavior, so test files need no
adjusting
);
/**
@@ -337,7 +338,6 @@
$ldif->done();
// Compare files, with expected attr adjusted
- $expected[33] = preg_replace('/attr6:: OmJhZGluaXRjaGFy/', 'attr6:
:badinitchar', $expected[33]);
$this->assertEquals($expected, file($this->outfile));
@@ -351,6 +351,38 @@
}
/**
+ * Test version writing
+ *
+ * In the default config, we supply a version which causes the ldif writer to
+ * spill out a version int. However, since 2.0.0RC5, the default behavior changed,
+ * so that no version is written by default (compatibility to perl interface).
+ * The following code tests that new behavior.
+ */
+ public function testWriteVersion() {
+ $testconf = $this->defaultConfig;
+
+ $expected = array_map('conv_lineend',
file(dirname(__FILE__).'/ldif_data/unsorted_w50.ldif'));
+ // strip 4 starting lines because of comments in the file header:
+ array_shift($expected);array_shift($expected);
+ array_shift($expected);array_shift($expected);
+
+ // strip 1 additional line (the "version: 1" line that should not be written now)
+ // and adjust test config
+ array_shift($expected);
+ unset($testconf['version']);
+
+ // Write LDIF
+ $ldif = new Net_LDAP2_LDIF($this->outfile, 'w', $testconf);
+ $this->assertTrue(is_resource($ldif->handle()));
+ $ldif->write_entry($this->testentries);
+ $this->assertFalse((boolean)$ldif->error(), 'Failed writing entry to
'.$this->outfile.': '.$ldif->error(true));
+ $ldif->done();
+
+ // Compare files
+ $this->assertEquals($expected, file($this->outfile));
+ }
+
+ /**
* Round trip test: Read LDIF, parse to entries, write that to LDIF and compare both files
*/
public function testReadWriteRead() {
@@ -641,17 +673,15 @@
Net_LDAP2_LDIFTest::main();
}
-if (!function_exists('conv_lineend')) {
- /**
- * Function transfers line endings to current OS
- *
- * This is neccessary to make write tests platform indendent.
- *
- * @param string $line Line
- * @return string
- */
- function conv_lineend($line) {
- return rtrim($line).PHP_EOL;
- }
+/**
+* Function transfers line endings to current OS
+*
+* This is neccessary to make write tests platform indendent.
+*
+* @param string $line Line
+* @return string
+*/
+function conv_lineend($line) {
+ return rtrim($line).PHP_EOL;
}
-?>
\ No newline at end of file
+?>