From 296293145424297b175b44f83813cf4c1d1c92db Mon Sep 17 00:00:00 2001 From: Fabrice Luraine Date: Sat, 5 Dec 2009 13:15:50 +0100 Subject: [PATCH] Adding a security option that prevents output in require_once_dir ($prevents_output is true by default) --- lib/limonade.php | 7 ++++--- tests/main.php | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/limonade.php b/lib/limonade.php index ad027d8..89e43e4 100644 --- a/lib/limonade.php +++ b/lib/limonade.php @@ -1761,16 +1761,17 @@ function v($value, $default) * * @param string $path Path in which are the file to load * @param string $pattern a regexp pattern that filter files to load + * @param bool $prevents_output security option that prevents output * @return array paths of loaded files */ -function require_once_dir($path, $pattern = "*.php") +function require_once_dir($path, $pattern = "*.php", $prevents_output = true) { if($path[strlen($path) - 1] != "/") $path .= "/"; $filenames = glob($path.$pattern); if(!is_array($filenames)) $filenames = array(); - ob_start(); + if($prevents_output) ob_start(); foreach($filenames as $filename) require_once $filename; - ob_end_clean(); + if($prevents_output) ob_end_clean(); return $filenames; } diff --git a/tests/main.php b/tests/main.php index 5d52b24..1601ec3 100644 --- a/tests/main.php +++ b/tests/main.php @@ -128,11 +128,17 @@ function test_main_require_once_dir() ob_start(); assert_empty(require_once_dir($root)); $files = require_once_dir($root, "AUTHORS"); + assert_empty(ob_get_contents()); ob_clean(); assert_length_of($files, 1); assert_match('/AUTHORS$/', $files[0]); + ob_start(); + $files = require_once_dir($root, "CHANGES", false); + assert_not_empty(ob_get_contents()); + ob_clean(); + $lib = $root.'/lib'; $limonade = $lib.'/limonade';