Skip to content

Commit

Permalink
MDL-16919 - Convert uppercase to lowercase for param_username and upd…
Browse files Browse the repository at this point in the history
…ating test result in testmoodlelib.
  • Loading branch information
rwijaya committed Jan 14, 2010
1 parent 1edad60 commit 34d2b19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,12 @@ function clean_param($param, $type) {

case PARAM_USERNAME:
$param = str_replace(" " , "", $param);
if (empty($CFG->extendedusernamechars)) {
$param = moodle_strtolower($param); // Convert uppercase to lowercase MDL-16919
if (empty($CFG->extendedusernamechars)) {
// regular expression, eliminate all chars EXCEPT:
// alphanum, dash (-), underscore (_), at sign (@) and period (.) characters.
$param = preg_replace('/[^-\.@_a-z0-9]/', '', $param);
} else {
$param = preg_replace('/[A-Z]/', '', $param);
}
}
return $param;

default: // throw error, switched parameters in optional_param or another serious problem
Expand Down
8 changes: 4 additions & 4 deletions lib/simpletest/testmoodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ function test_clean_param() {
$this->assertEqual(clean_param('john~doe', PARAM_USERNAME), 'johndoe');
$this->assertEqual(clean_param('john´doe', PARAM_USERNAME), 'johndoe');
$this->assertEqual(clean_param('john#$%&() ', PARAM_USERNAME), 'john');
$this->assertEqual(clean_param('JOHNdóé ', PARAM_USERNAME), 'd');
$this->assertEqual(clean_param('john.,:;-_/|\ñÑ[]A_X-,D {} ~!@#$%^&*()_+ ?><[] ščřžžý ?ýáž?žý??šdoe ', PARAM_USERNAME), 'john.-__-@_doe');
$this->assertEqual(clean_param('JOHNdóé ', PARAM_USERNAME), 'johnd');
$this->assertEqual(clean_param('john.,:;-_/|\ñÑ[]A_X-,D {} ~!@#$%^&*()_+ ?><[] ščřžžý ?ýáž?žý??šdoe ', PARAM_USERNAME), 'john.-_a_x-d@_doe');


// Test success condition, if extendedusernamechars == ENABLE;
Expand All @@ -320,8 +320,8 @@ function test_clean_param() {
$this->assertEqual(clean_param('john@doe', PARAM_USERNAME), 'john@doe');
$this->assertEqual(clean_param('john# $%&()+_^', PARAM_USERNAME), 'john#$%&()+_^');
$this->assertEqual(clean_param('john~doe', PARAM_USERNAME), 'john~doe');
$this->assertEqual(clean_param('joHN´doe', PARAM_USERNAME), 'jo´doe');
$this->assertEqual(clean_param('johnDOE', PARAM_USERNAME), 'john');
$this->assertEqual(clean_param('joHN´doe', PARAM_USERNAME), 'john´doe');
$this->assertEqual(clean_param('johnDOE', PARAM_USERNAME), 'johndoe');
$this->assertEqual(clean_param('johndóé ', PARAM_USERNAME), 'johndóé');

$CFG->extendedusernamechars = $currentstatus;
Expand Down

0 comments on commit 34d2b19

Please sign in to comment.