Skip to content

Commit

Permalink
[mms] Relax overly strict string type checking when compressing/decom…
Browse files Browse the repository at this point in the history
…pressing.
  • Loading branch information
slusarz committed Jul 8, 2014
1 parent 6879022 commit edb2959
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
8 changes: 4 additions & 4 deletions framework/Compress_Fast/lib/Horde/Compress/Fast.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public function __get($name)
*/
public function compress($text)
{
if (!is_string($text)) {
if (!is_scalar($text) && !is_null($text)) {
throw new Horde_Compress_Fast_Exception('Data to compress must be a string.');
}

return $this->_compress->compress($text);
return $this->_compress->compress(strval($text));
}

/**
Expand All @@ -103,11 +103,11 @@ public function compress($text)
*/
public function decompress($text)
{
if (!is_string($text)) {
if (!is_scalar($text) && !is_null($text)) {
throw new Horde_Compress_Fast_Exception('Data to decompress must be a string.');
}

return $this->_compress->decompress($text);
return $this->_compress->decompress(strval($text));
}

}
4 changes: 2 additions & 2 deletions framework/Compress_Fast/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Relax overly strict string type checking when compressing/decompressing.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -168,7 +168,7 @@
<date>2013-07-16</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Relax overly strict string type checking when compressing/decompressing.
</notes>
</release>
</changelog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,42 @@ public function testLz4DriverDecompress()
} catch (Horde_Compress_Fast_Exception $e) {}
}

/**
* @dataProvider providerTestStringInput
*/
public function testStringInput($data, $success)
{
$ob = new Horde_Compress_Fast(array(
'drivers' => array(
'Horde_Compress_Fast_Null'
)
));

try {
$ob->compress($data);
if (!$success) {
$this->fail('Expected exception.');
}
} catch (Horde_Compress_Fast_Exception $e) {
if ($success) {
$this->fail('Unexpected exception.');
}
}
}

public function providerTestStringInput()
{
// Format: data, expected success
return array(
array('a', true),
array(0.1, true),
array(1, true),
array(true, true),
array(null, true),
array(array(), false),
array(new stdClass, false),
array(opendir(__DIR__), false)
);
}

}

0 comments on commit edb2959

Please sign in to comment.