summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/helpers/album.php9
-rw-r--r--core/helpers/photo.php7
-rw-r--r--core/tests/Album_Helper_Test.php13
-rw-r--r--core/tests/Movie_Helper_Test.php34
-rw-r--r--core/tests/Photo_Helper_Test.php14
5 files changed, 74 insertions, 3 deletions
diff --git a/core/helpers/album.php b/core/helpers/album.php
index fc6368f8..7c667751 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -37,6 +37,10 @@ class album_Core {
throw new Exception("@todo INVALID_PARENT");
}
+ if (strpos($name, "/")) {
+ throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
+ }
+
$album = ORM::factory("item");
$album->type = "album";
$album->title = $title;
@@ -68,7 +72,8 @@ class album_Core {
static function get_add_form($parent) {
$form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gAddAlbumForm"));
- $group = $form->group("add_album")->label(t("Add an album to %album_title", array("album_title" => $parent->title)));
+ $group = $form->group("add_album")
+ ->label(t("Add an album to %album_title", array("album_title" => $parent->title)));
$group->input("title")->label(t("Title"));
$group->textarea("description")->label(t("Description"));
$group->input("name")->label(t("Directory Name"));
@@ -86,7 +91,7 @@ class album_Core {
$group->input("title")->label(t("Title"))->value($parent->title);
$group->textarea("description")->label(t("Description"))->value($parent->description);
if ($parent->id != 1) {
- $group->input("name")->label(t("Directory Name"))->value($parent->name);
+ $group->dirname->label(t("Directory Name"))->value($parent->name);
}
$sort_order = $group->group("sort_order", array("id" => "gAlbumSortOrder"))
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index ff4936b4..6467e797 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -43,6 +43,10 @@ class photo_Core {
throw new Exception("@todo MISSING_IMAGE_FILE");
}
+ if (strpos($name, "/")) {
+ throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
+ }
+
$image_info = getimagesize($filename);
// Force an extension onto the name
@@ -124,7 +128,8 @@ class photo_Core {
$group = $form->group("edit_photo")->label(t("Edit Photo"));
$group->input("title")->label(t("Title"))->value($photo->title);
$group->textarea("description")->label(t("Description"))->value($photo->description);
- $group->input("name")->label(t("Filename"))->value($photo->name);
+ $group->input("filename")->label(t("Filename"))->value($photo->name)
+ ->error_messages("conflict", t("There is already a file with this name"));
$group->submit("")->value(t("Modify"));
$form->add_rules_from(ORM::factory("item"));
return $form;
diff --git a/core/tests/Album_Helper_Test.php b/core/tests/Album_Helper_Test.php
index d4bfca55..522d58d9 100644
--- a/core/tests/Album_Helper_Test.php
+++ b/core/tests/Album_Helper_Test.php
@@ -58,4 +58,17 @@ class Album_Helper_Test extends Unit_Test_Case {
$album = album::create($root, $rand, $rand, $rand);
$this->assert_equal("http://./var/resizes/$rand/.album.jpg", $album->resize_url());
}
+
+ public function create_album_shouldnt_allow_names_with_slash_test() {
+ $rand = rand();
+ $root = ORM::factory("item", 1);
+ try {
+ $album = album::create($root, $rand . "/", $rand, $rand);
+ } catch (Exception $e) {
+ // pass
+ return;
+ }
+
+ $this->assert_true(false, "Shouldn't create an album with / in the name");
+ }
}
diff --git a/core/tests/Movie_Helper_Test.php b/core/tests/Movie_Helper_Test.php
new file mode 100644
index 00000000..0899154e
--- /dev/null
+++ b/core/tests/Movie_Helper_Test.php
@@ -0,0 +1,34 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Movie_Helper_Test extends Unit_Test_Case {
+ public function create_movie_shouldnt_allow_names_with_slash_test() {
+ $rand = rand();
+ $root = ORM::factory("item", 1);
+ try {
+ $filename = DOCROOT . "core/tests/test.jpg";
+ $photo = photo::create($root, $filename, "$rand/.jpg", $rand, $rand);
+ } catch (Exception $e) {
+ // pass
+ return;
+ }
+
+ $this->assert_true(false, "Shouldn't create a movie with / in the name");
+ }
+}
diff --git a/core/tests/Photo_Helper_Test.php b/core/tests/Photo_Helper_Test.php
index 45e911b2..81405b79 100644
--- a/core/tests/Photo_Helper_Test.php
+++ b/core/tests/Photo_Helper_Test.php
@@ -80,4 +80,18 @@ class Photo_Helper_Test extends Unit_Test_Case {
$this->assert_equal("http://./var/resizes/{$rand}/{$rand}.jpg", $photo->resize_url());
}
+
+ public function create_photo_shouldnt_allow_names_with_slash_test() {
+ $rand = rand();
+ $root = ORM::factory("item", 1);
+ try {
+ $filename = DOCROOT . "core/tests/test.jpg";
+ $photo = photo::create($root, $filename, "$rand/.jpg", $rand, $rand);
+ } catch (Exception $e) {
+ // pass
+ return;
+ }
+
+ $this->assert_true(false, "Shouldn't create a photo with / in the name");
+ }
}