From 78db1bb339042f3aadb5a61bfe26ddd20c4b8951 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 4 Apr 2010 14:27:39 -0700 Subject: Fix a bug where if the file name is composed of entirely illegal characters, we'll get an empty slug. Partial fix for #1086. --- modules/gallery/models/item.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 6ede5109..1026264f 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -332,6 +332,12 @@ class Item_Model extends ORM_MPTT { $tmp = pathinfo($this->name, PATHINFO_FILENAME); $tmp = preg_replace("/[^A-Za-z0-9-_]+/", "-", $tmp); $this->slug = trim($tmp, "-"); + + // If the filename is all invalid characters, then the slug may be empty here. Pick a + // random value. + if (empty($this->slug)) { + $this->slug = (string)rand(1000, 9999); + } } // Get the width, height and mime type from our data file for photos and movies. -- cgit v1.2.3