summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-12-21 16:55:01 -0800
committerBharat Mediratta <bharat@menalto.com>2010-12-21 16:55:01 -0800
commitf493130e59f26d41f090c5ca40e95b416b9b154b (patch)
tree318c3803b1c9d9ced08faca3ee5e74000a1bb0fc
parentc7096cc9ebe4b737c06629b975317aaa9806297f (diff)
Tighten up item::find_by_path slightly. Augment the tests to cover
special characters in the file name ("+" is an edge case differentiator between rawurlencode and urlencode).
-rw-r--r--modules/gallery/helpers/item.php25
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php2
2 files changed, 13 insertions, 14 deletions
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index f38d9888..3596a2bf 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -210,33 +210,32 @@ class item_Core {
}
/**
- * Return an item by path.
+ * Find an item by its path. If there's no match, return an empty Item_Model.
* @param string $path
- * @return object item
+ * @return object Item_Model
*/
static function find_by_path($path) {
$path = trim($path, "/");
-
- // The root path name is NULL, not '', hence this workaround.
- if ($path == '') {
- return ORM::factory("item", item::root());
+
+ // The root path name is NULL not "", hence this workaround.
+ if ($path == "") {
+ return item::root();
}
-
+
$paths = explode("/", $path);
- $count = count($paths);
foreach (ORM::factory("item")
- ->where("name", "=", $paths[$count - 1])
- ->where("level", "=", $count + 1)
+ ->where("name", "=", end($paths))
+ ->where("level", "=", count($paths) + 1)
->find_all() as $item) {
if (urldecode($item->relative_path()) == $path) {
return $item;
}
}
-
+
return false;
}
-
-
+
+
/**
* Return the root Item_Model
* @return Item_Model
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index d60380f0..4124e453 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -135,7 +135,7 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
$level2b = test::random_album($level1);
$level3b = test::random_photo($level2b);
- $level3b->name = "same.jpg";
+ $level3b->name = "has spaces+plusses.jpg";
$level3b->save();
// Item in album