mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
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.
This commit is contained in:
parent
8673a98d1d
commit
5230f6a720
11
mdeploy.php
11
mdeploy.php
@ -264,8 +264,17 @@ class input_manager extends singleton_pattern {
|
||||
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);
|
||||
|
@ -144,7 +144,9 @@ class mdeploytest extends PHPUnit_Framework_TestCase {
|
||||
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'),
|
||||
|
||||
@ -163,6 +165,30 @@ class mdeploytest extends PHPUnit_Framework_TestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user