From 8ffa8d7e480f8ae0f1aec282feea5a20aa2df4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 7 Nov 2012 21:54:22 +0100 Subject: [PATCH] MDL-35238 Be more verbose if the tilde character is used in TYPE_PATH script options The tilde character is not generally supported in Moodle. Previously it was just removed silently and it was difficult to realize what was going on. --- mdeploy.php | 3 +++ mdeploytest.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/mdeploy.php b/mdeploy.php index a724cb6fbdb..27f50262fa0 100644 --- a/mdeploy.php +++ b/mdeploy.php @@ -258,6 +258,9 @@ class input_manager extends singleton_pattern { return (int)$raw; case input_manager::TYPE_PATH: + if (strpos($raw, '~') !== false) { + throw new invalid_option_exception('Using the tilde (~) character in paths is not supported'); + } $raw = str_replace('\\', '/', $raw); $raw = preg_replace('~[[:cntrl:]]|[&<>"`\|\':]~u', '', $raw); $raw = preg_replace('~\.\.+~', '', $raw); diff --git a/mdeploytest.php b/mdeploytest.php index eb3332f1adb..471a9d33eae 100644 --- a/mdeploytest.php +++ b/mdeploytest.php @@ -174,6 +174,15 @@ class mdeploytest extends PHPUnit_Framework_TestCase { $input->cast_value($invalid, input_manager::TYPE_MD5); // must throw exception } + /** + * @expectedException invalid_option_exception + */ + public function test_cast_tilde_in_path() { + $input = testable_input_manager::instance(); + $invalid = '~/public_html/moodle_dev'; + $input->cast_value($invalid, input_manager::TYPE_PATH); // must throw exception + } + public function test_has_option() { $provider = input_fake_provider::instance();