From e592d69fc24d9bc0319b84f001a8ed89fb5a67d8 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 11 May 2015 15:14:10 +0200 Subject: [PATCH] [ldap] Fix exceptions while parsing are not captured. Fix zendframework/zf2#7512 --- src/Attribute.php | 2 +- src/Converter/Converter.php | 10 +++++++++- test/AttributeTest.php | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Attribute.php b/src/Attribute.php index 80524c06a..6ee974c2f 100644 --- a/src/Attribute.php +++ b/src/Attribute.php @@ -197,7 +197,7 @@ private static function valueFromLdap($value) } else { return $return; } - } catch (Exception\InvalidArgumentException $e) { + } catch (Converter\Exception\InvalidArgumentException $e) { return $value; } } diff --git a/src/Converter/Converter.php b/src/Converter/Converter.php index 3ed122dad..5bf4a035c 100644 --- a/src/Converter/Converter.php +++ b/src/Converter/Converter.php @@ -339,7 +339,15 @@ public static function fromLdapDateTime($date, $asUtc = true) . $time['offdir'] . str_pad($time['offsethours'], 2, '0', STR_PAD_LEFT) . str_pad($time['offsetminutes'], 2, '0', STR_PAD_LEFT); - $date = new DateTime($timestring); + try { + $date = new DateTime($timestring); + } catch (\Exception $e) { + throw new Exception\InvalidArgumentException( + 'Invalid date format found', + 0, + $e + ); + } if ($asUtc) { $date->setTimezone(new DateTimeZone('UTC')); } diff --git a/test/AttributeTest.php b/test/AttributeTest.php index 4ac9993e5..776a5054b 100644 --- a/test/AttributeTest.php +++ b/test/AttributeTest.php @@ -51,6 +51,14 @@ public function testGetNonExistentAttributeValue() $this->assertNull($value); } + public function testInvalidValue() + { + $data = array('uid' => array('45678+')); + $value = Attribute::getAttribute($data, 'uid', 0); + + $this->assertEquals('45678+', $value); + } + public function testGetNonExistentAttribute() { $data = array('uid' => array('value'));