summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/models/item.php6
-rw-r--r--modules/gallery/tests/Item_Model_Test.php6
2 files changed, 12 insertions, 0 deletions
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.
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index d0676292..8ab85a30 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -324,6 +324,12 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
$album->save();
}
+ public function name_with_only_invalid_chars_is_still_valid_test() {
+ $album = test::random_album_unsaved();
+ $album->name = "[]";
+ $album->save();
+ }
+
public function cant_change_item_type_test() {
$photo = test::random_photo();
try {