diff --git a/lib/Gedmo/Sluggable/SluggableListener.php b/lib/Gedmo/Sluggable/SluggableListener.php index e0fa5e6048..d2b2c7a1b3 100644 --- a/lib/Gedmo/Sluggable/SluggableListener.php +++ b/lib/Gedmo/Sluggable/SluggableListener.php @@ -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; } diff --git a/tests/Gedmo/Sluggable/Issue/Issue131Test.php b/tests/Gedmo/Sluggable/Issue/Issue131Test.php index 0f0e13e14b..4af810568e 100644 --- a/tests/Gedmo/Sluggable/Issue/Issue131Test.php +++ b/tests/Gedmo/Sluggable/Issue/Issue131Test.php @@ -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(