Skip to content

Commit

Permalink
MDL-35238 Be more verbose if the tilde character is used in TYPE_PATH…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
mudrd8mz committed Nov 8, 2012
1 parent ec8e1cb commit 8ffa8d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mdeploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ public function cast_value($raw, $type) {
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);
Expand Down
9 changes: 9 additions & 0 deletions mdeploytest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ public function test_cast_invalid_md5_value() {
$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();

Expand Down

0 comments on commit 8ffa8d7

Please sign in to comment.