Skip to content

Commit

Permalink
[new_profile/sex] Remove strtolower() and force uppercase (#8633)
Browse files Browse the repository at this point in the history
The keys in the new_profile module were lower case which forces the Sex library class to use a strtolower() function to validate the value and then submits the lowercase value in the SQL insert statement where SQL implicitly converts it to uppercase. This workflow is very risky as different versions of SQL or different databases may not recognise the lowercase and uppercase as the same word and treat it as a truncation. This is also simply bad practice and unnecessary here.
  • Loading branch information
ridz1208 authored May 2, 2023
1 parent 4c58152 commit 577e3a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions modules/new_profile/php/new_profile.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ class New_Profile extends \NDB_Form
$dobFormat = $config->getSetting('dobFormat');
$edc = $config->getSetting('useEDC');
$sex = [
'male' => 'Male',
'female' => 'Female',
'other' => 'Other',
'Male' => 'Male',
'Female' => 'Female',
'Other' => 'Other',
];
$pscidSet = "false";
$minYear = (isset($startYear, $ageMax)) ? $startYear - $ageMax : null;
Expand Down
2 changes: 1 addition & 1 deletion modules/new_profile/test/new_profileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function testNewProfileCreateCandidate(): void
// send a key to sex
$sexElement = $this->safeFindElement(WebDriverBy::Name('sex'));
$sexOption = new WebDriverSelect($sexElement);
$sexOption->selectByValue("male");
$sexOption->selectByValue("Male");
$sexElement = $this->safeFindElement(WebDriverBy::Name('site'));
$sexOption = new WebDriverSelect($sexElement);
$sexOption->selectByValue("1");
Expand Down
8 changes: 4 additions & 4 deletions src/StudyEntities/Candidate/Sex.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Sex implements \JsonSerializable
public $value;

private const VALID_VALUES = array(
'male',
'female',
'other',
'Male',
'Female',
'Other',
);

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ public function __construct(string $value)
*/
public static function validate(string $value): bool
{
return in_array(strtolower($value), self::VALID_VALUES, true);
return in_array($value, self::VALID_VALUES, true);
}

/**
Expand Down

0 comments on commit 577e3a7

Please sign in to comment.