Skip to content

Commit ca395ba

Browse files
committed
nullable slug must not be null if base field has "0"
1 parent c186806 commit ca395ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Gedmo/Sluggable/SluggableListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private function generateSlug(SluggableAdapter $ea, $object)
381381
$slug = substr($slug, 0, $mapping['length']);
382382
}
383383

384-
if (isset($mapping['nullable']) && $mapping['nullable'] && !$slug) {
384+
if (isset($mapping['nullable']) && $mapping['nullable'] && strlen($slug) === 0) {
385385
$slug = null;
386386
}
387387

tests/Gedmo/Sluggable/Issue/Issue131Test.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public function testSlugGeneration()
4646
$this->assertNull($test2->getSlug());
4747
}
4848

49+
/**
50+
* @test
51+
*/
52+
public function shouldHandleOnlyZeroInSlug()
53+
{
54+
$article = new Article();
55+
$article->setTitle('0');
56+
57+
$this->em->persist($article);
58+
$this->em->flush();
59+
60+
$this->assertEquals('0', $article->getSlug());
61+
}
62+
4963
protected function getUsedEntityFixtures()
5064
{
5165
return array(

0 commit comments

Comments
 (0)