Skip to content

Commit

Permalink
Merge pull request #1768 from vetalt/shouldHandleOnlyZeroInSlug
Browse files Browse the repository at this point in the history
nullable slug must not be null if base field has "0"
  • Loading branch information
l3pp4rd authored Mar 22, 2017
2 parents c186806 + ca395ba commit fe152e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Gedmo/Sluggable/SluggableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private function generateSlug(SluggableAdapter $ea, $object)
$slug = substr($slug, 0, $mapping['length']);
}

if (isset($mapping['nullable']) && $mapping['nullable'] && !$slug) {
if (isset($mapping['nullable']) && $mapping['nullable'] && strlen($slug) === 0) {
$slug = null;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Gedmo/Sluggable/Issue/Issue131Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ public function testSlugGeneration()
$this->assertNull($test2->getSlug());
}

/**
* @test
*/
public function shouldHandleOnlyZeroInSlug()
{
$article = new Article();
$article->setTitle('0');

$this->em->persist($article);
$this->em->flush();

$this->assertEquals('0', $article->getSlug());
}

protected function getUsedEntityFixtures()
{
return array(
Expand Down

0 comments on commit fe152e1

Please sign in to comment.