Skip to content

Commit

Permalink
MDL-45221 admin: configexecutable admin settings should only accept f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
andrewnicols committed Apr 28, 2014
1 parent e865dff commit 9cd7bb3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ public function output_html($data, $query='') {
$default = $this->get_defaultsetting();

if ($data) {
if (file_exists($data) and is_executable($data)) {
if (file_exists($data) and !is_dir($data) and is_executable($data)) {
$executable = '<span class="pathok">&#x2714;</span>';
} else {
$executable = '<span class="patherror">&#x2718;</span>';
Expand Down
30 changes: 30 additions & 0 deletions lib/tests/admintree_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ public function test_add_nodes_before_invalid2() {
$tree->add('root', new admin_category('bar', 'Bar'), '');
}

/**
* Testing whether a configexecutable setting is executable.
*/
public function test_admin_setting_configexecutable() {
global $CFG;
$this->resetAfterTest();

$executable = new admin_setting_configexecutable('test1', 'Text 1', 'Help Path', '');

// Check for an invalid path.
$result = $executable->output_html($CFG->dirroot . '/lib/tests/other/file_does_not_exist');
$this->assertRegexp('/class="patherror"/', $result);

// Check for a directory.
$result = $executable->output_html($CFG->dirroot);
$this->assertRegexp('/class="patherror"/', $result);

// Check for a file which is not executable.
$result = $executable->output_html($CFG->dirroot . '/config.php');
$this->assertRegexp('/class="patherror"/', $result);

// Check for an executable file.
$result = $executable->output_html($CFG->dirroot . '/lib/tests/other/executable.php');
$this->assertRegexp('/class="pathok"/', $result);

// Check for no file specified.
$result = $executable->output_html('');
$this->assertRegexp('/name="s__test1" value=""/', $result);
}

/**
* Saving of values.
*/
Expand Down
Empty file added lib/tests/other/executable.php
Empty file.

0 comments on commit 9cd7bb3

Please sign in to comment.