If you do not choose the day of your birthday and just the month and the year you get this on the profile page:
Quote:Date of Birth: 00.11.83 (25 years old)
Another user reported that in his forums the date of last day of the month before is shown if he does not choose a day.
I've been playing this morning with this. It seems, with some date formats, an empty month can interfere too.
The only way I've managed to 100% prevent this bug is this; in ./inc/datahandlers/user.php, find:
// Error if a day and month exists, and the birthday day and range is not in range
if($birthday['day'] && $birthday['month'])
Add above:
// Pull below 0 to hit error if no input is given
if(!$birthday['day'])
{
$birthday['day'] = -1;
}
if(!$birthday['month'])
{
$birthday['month'] = -1;
}
If it's already under 1 it would give an invalid birthday though. As it is int validated it would be 0 if no input is given..
(2009-06-08, 07:40 AM)CraKteR Wrote: [ -> ]If it's already under 1 it would give an invalid birthday though.
No, it doesn't - that's why I made that to pull it under 0. Making it int validated makes it 0, which means no input. MyBB then does this:
if($birthday['day'] && $birthday['month'])
{
if($birthday['day'] < 1 || $birthday['day'] > 31...
This if statement is where the error is activated, but there is no $birthday['day'], so if the user inputs nothing then the error doesn't get activated. Making it -1 gives $birthday['day'] a value, therefore going through the if statement.
Further reinforcing the fact that I should never eat and develop at the same time, this has the same effect but I think is a better fix:
// Error if a day and month exists, and the birthday day and range is not in range
if($birthday['day'] && $birthday['month'])
{
...
}
else
{
$this->set_error("invalid_birthday");
return false;
}
If there isn't a day and month (as required) the error is shown.
(2009-06-10, 08:56 AM)Tomm M Wrote: [ -> ] (2009-06-08, 07:40 AM)CraKteR Wrote: [ -> ]If it's already under 1 it would give an invalid birthday though.
No, it doesn't - that's why I made that to pull it under 0. Making it int validated makes it 0, which means no input.
Since it is int 0 means 0, not no input.
Why not just delete the line with the check that it's inputted, because it will check that it is above 1 anyways. Since it is intval'ed it will be a number anyways. So no input means 0 which will through an error.
if($birthday['day'] && $birthday['month'])
{
if($birthday['day'] < 1 || $birthday['day'] > 31 || $birthday['month'] < 1 || $birthday['month'] > 12 || ($birthday['month'] == 2 && $birthday['day'] > 29))
{
$this->set_error("invalid_birthday");
return false;
}
// Check if the day actually exists.
$months = get_bdays($birthday['year']);
if($birthday['day'] > $months[$birthday['month']-1])
{
$this->set_error("invalid_birthday");
return false;
}
}
to
if($birthday['day'] < 1 || $birthday['day'] > 31 || $birthday['month'] < 1 || $birthday['month'] > 12 || ($birthday['month'] == 2 && $birthday['day'] > 29))
{
$this->set_error("invalid_birthday");
return false;
}
// Check if the day actually exists.
$months = get_bdays($birthday['year']);
if($birthday['day'] > $months[$birthday['month']-1])
{
$this->set_error("invalid_birthday");
return false;
}
That way it will give an invalid_birthday error because $birthday['day'] is below 1.
That line is unnecessary because it's intval'ed.
I do believe CraKteR is correct. Intval will return 0 if it is not something that it can convert to an integer. Therefore 0 is the input that it sees, not null or an empty string.
I guess "no input" is not really what I'm trying to say... Not trying to insult intelligence, but just to explain what I mean:
$content = ''; // No input from the birthday day
$test = intval($content); // = '0'
if($test)
{
echo "true";
}
else
{
echo "false";
}
$content is the birthday['day'], intval'd would mean that this is now 0 ($test). Put through the if statement, it returns false. It's the same that happens in this bug - because $birthday['day'] is 0, it doesn't go through the if statement, and the invalid birthday error isn't returned.
That's why you can remove the
if($birthday['day'] && $birthday['month'])
line with ease. It already throws an error if day is < 1 (if that line isn't there), no need for another error message as it would be redundant code.
(2009-06-10, 03:28 PM)Tomm M Wrote: [ -> ]I guess "no input" is not really what I'm trying to say... Not trying to insult intelligence, but just to explain what I mean:
$content = ''; // No input from the birthday day
$test = intval($content); // = '0'
if($test)
{
echo "true";
}
else
{
echo "false";
}
$content is the birthday['day'], intval'd would mean that this is now 0 ($test). Put through the if statement, it returns false. It's the same that happens in this bug - because $birthday['day'] is 0, it doesn't go through the if statement, and the invalid birthday error isn't returned.
Why is why CraKteR's fix of removing that one if statement all together is better.
(2009-06-10, 03:46 PM)Ryan Gordon Wrote: [ -> ]Why is why CraKteR's fix of removing that one if statement all together is better.
Like I said... I was just explaining...