MDL-35238 Be more verbose if the tilde character is used in TYPE_PATH script options
authorDavid Mudrák <david@moodle.com>
Wed, 7 Nov 2012 20:54:22 +0000 (21:54 +0100)
committerDavid Mudrák <david@moodle.com>
Thu, 8 Nov 2012 21:33:07 +0000 (22:33 +0100)
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
mdeploytest.php

index a724cb6..27f5026 100644 (file)
@@ -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);
index eb3332f..471a9d3 100644 (file)
@@ -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();