Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Adapter/PhpSerialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function serialize($value)
*/
public function unserialize($serialized)
{
if (!is_string($serialized) || !preg_match('/^((s|i|d|b|a|O|C):|N;)/', $serialized)) {
return $serialized;
if (!is_string($serialized)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do note understand why you're removing this check.

The regular expression there ensures that we don't run an unserialize() call unnecessarily; if the string is clearly invalid, there's no reason to make the attempt.

We can still throw the exception; I just think we should keep the preg_match too.

throw new Exception\RuntimeException('Serialized data must be a string');
}

// If we have a serialized boolean false value, just return false;
Expand Down
12 changes: 8 additions & 4 deletions test/Adapter/PhpSerializeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,19 @@ public function testUnserializeObject()
$this->assertEquals($expected, $data);
}

public function testUnserializingNonserializedStringReturnsItVerbatim()
public function testUnserializingNoStringRaisesException()
{
$value = 'not a serialized string';
$this->assertEquals($value, $this->adapter->unserialize($value));
$value = null;
$this->setExpectedException(
'Zend\Serializer\Exception\RuntimeException',
'Serialized data must be a string'
);
$this->adapter->unserialize($value);
}

public function testUnserializingInvalidStringRaisesException()
{
$value = 'a:foobar';
$value = 'foobar';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue the change in this test is indicative of exactly the situation I outlined above. If anything, this test should be expanded to use a data provider to try several different strings.

$this->setExpectedException('Zend\Serializer\Exception\RuntimeException');
$this->adapter->unserialize($value);
}
Expand Down