Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-38456 Allow colons in paths passed to mdeploy.php utility

The input_manager now accepts colons (:) in TYPE_PATH options, but only
in cases where the colon is used as a part of Windows drive labels, as
in C:\apache.
  • Loading branch information...
commit a1ba9e89d92bc11acc63da9af375561ce1ae0e28 1 parent 5c8860f
@mudrd8mz mudrd8mz authored
Showing with 37 additions and 2 deletions.
  1. +10 −1 mdeploy.php
  2. +27 −1 mdeploytest.php
View
11 mdeploy.php
@@ -264,8 +264,17 @@ public function cast_value($raw, $type) {
if (strpos($raw, '~') !== false) {
throw new invalid_option_exception('Using the tilde (~) character in paths is not supported');
}
+ $colonpos = strpos($raw, ':');
+ if ($colonpos !== false) {
+ if ($colonpos !== 1 or strrpos($raw, ':') !== 1) {
+ throw new invalid_option_exception('Using the colon (:) character in paths is supported for Windows drive labels only.');
+ }
+ if (preg_match('/^[a-zA-Z]:/', $raw) !== 1) {
+ throw new invalid_option_exception('Using the colon (:) character in paths is supported for Windows drive labels only.');
+ }
+ }
$raw = str_replace('\\', '/', $raw);
- $raw = preg_replace('~[[:cntrl:]]|[&<>"`\|\':]~u', '', $raw);
+ $raw = preg_replace('~[[:cntrl:]]|[&<>"`\|\']~u', '', $raw);
$raw = preg_replace('~\.\.+~', '', $raw);
$raw = preg_replace('~//+~', '/', $raw);
$raw = preg_replace('~/(\./)+~', '/', $raw);
View
28 mdeploytest.php
@@ -144,7 +144,9 @@ public function data_for_cast_value() {
array('0', input_manager::TYPE_FLAG, true),
array('muhehe', input_manager::TYPE_FLAG, true),
- array('C:\\WINDOWS\\user.dat', input_manager::TYPE_PATH, 'C/WINDOWS/user.dat'),
+ array('C:\\WINDOWS\\user.dat', input_manager::TYPE_PATH, 'C:/WINDOWS/user.dat'),
+ array('D:\xampp\htdocs\24_integration/mdeploy.php', input_manager::TYPE_PATH, 'D:/xampp/htdocs/24_integration/mdeploy.php'),
+ array('d:/xampp/htdocs/24_integration/mdeploy.php', input_manager::TYPE_PATH, 'd:/xampp/htdocs/24_integration/mdeploy.php'),
array('../../../etc/passwd', input_manager::TYPE_PATH, '/etc/passwd'),
array('///////.././public_html/test.php', input_manager::TYPE_PATH, '/public_html/test.php'),
@@ -164,6 +166,30 @@ public function data_for_cast_value() {
}
/**
+ * @expectedException invalid_option_exception
+ */
+ public function test_input_type_path_multiple_colons() {
+ $input = testable_input_manager::instance();
+ $input->cast_value('C:\apache\log:file', input_manager::TYPE_PATH); // must throw exception
+ }
+
+ /**
+ * @expectedException invalid_option_exception
+ */
+ public function test_input_type_path_invalid_drive_label() {
+ $input = testable_input_manager::instance();
+ $input->cast_value('0:/srv/moodledata', input_manager::TYPE_PATH); // must throw exception
+ }
+
+ /**
+ * @expectedException invalid_option_exception
+ */
+ public function test_input_type_path_invalid_colon() {
+ $input = testable_input_manager::instance();
+ $input->cast_value('/var/www/moodle:2.5', input_manager::TYPE_PATH); // must throw exception
+ }
+
+ /**
* @expectedException invalid_coding_exception
*/
public function test_cast_array_argument() {
Please sign in to comment.
Something went wrong with that request. Please try again.