?
avatar Ry-Fi
Ry-Fi
14 Oct 2015

Steps to reproduce the issue

  • Require Date of Birth (DOB) on User Profile
  • Attempt to Register a user using an invalid date for the DOB - ex: 1970-13-13

Expected result

  • Registration will fail, redirecting back to the registration form and showing the DOB validation error "Registration failed: The date of birth you entered is invalid. Please enter valid date." (PLG_USER_PROFILE_ERROR_INVALID_DOB)

Actual result

  • Instead, the redirect fails on the invalid date, resulting in a 500 error page showing "DateTime::__construct(): Failed to parse time string (1970-13-13) at position 6 (3): Unexpected character"

System information (as much as possible)

  • PHP 5.5.0RC3
  • MySQL 5.5.32

Additional comments

  • Should be trivial for someone else to try to reproduce and confirm or deny

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar Ry-Fi Ry-Fi - open - 14 Oct 2015
avatar zero-24
zero-24 - comment - 14 Oct 2015

Please try #7849 it should fix the issue with the next update to 3.4.5

avatar Ry-Fi
Ry-Fi - comment - 14 Oct 2015

Unfortunately that didn't fix it for me.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8093.

avatar infograf768
infograf768 - comment - 15 Oct 2015

I confirm the issue on staging

avatar Ry-Fi
Ry-Fi - comment - 15 Oct 2015

Thanks.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8093.

avatar ggppdk
ggppdk - comment - 15 Oct 2015

Actually this is 2 bugs, and both can effect other code and 3rd party extensions

  • Uncaught exception in filtering code
  • Uncaught exception after form reload if form validation fails (e.g. email exists)

Filtering types for 'SERVER_UTC' 'USER_UTC'
do not use try-catch, in

libraries\joomla\form\form.php

// Return an SQL formatted datetime string in UTC.
$return = JFactory::getDate($value, $offset)->toSql();

should (probably) be

// Return an SQL formatted datetime string in UTC.
try {
    $return = JFactory::getDate($value, $offset)->toSql();
} catch (Exception $e) {
    $return = '';
}

Similar the getInput() of calendar field (dob element extends calendar element)
on form-reload after validation will be given to display the invalid date that was posted

libraries\joomla\form\fields\calendar.php

// Get a date object based on the correct timezone.
$date = JFactory::getDate($this->value, 'UTC');

$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));

// Transform the date string.
$this->value = $date->format('Y-m-d H:i:s', true, false);

should (probably) be

try {
    // Get a date object based on the correct timezone.
    $date = JFactory::getDate($this->value, 'UTC');

    $date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));

    // Transform the date string.
    $this->value = $date->format('Y-m-d H:i:s', true, false);
} catch (Exception $e) {
    $this->value = '';
}

i can not do a pull request now,
but anyone else can do and also confirm fix,
and do whatever more is needed

avatar ggppdk
ggppdk - comment - 15 Oct 2015

and each of the above is needed in 2 places, (for both 'SERVER_UTC' and 'USER_UTC')

avatar Ry-Fi
Ry-Fi - comment - 15 Oct 2015

Thanks for your assessment of this issue.

Now forgive me, I'm not a Joomla contributor, just some schmoe trying to use it... but I've implemented the changes you're suggesting into my development work and this doesn't seem like the correct solution to me. Instead of resulting in the expected validation error, "Registration failed: The date of birth you entered is invalid. Please enter valid date.", this is instead resulting in a simple warning, "Field required: Date of Birth:", and resetting the entered date to today's date, which obfuscates the issue being that the user entered an invalid date. Therefore this doesn't really accomplish the correct fix that would be consistent with Joomla, in my opinion.

I will admit that I'm not very familiar with the form validation architecture to have any better idea of how this should be addressed, so I'm not really helpful in knowing what the correct solution would be... but surely the ideal fix is obvious to someone who's well-versed in this part of the system, no?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8093.

avatar ggppdk
ggppdk - comment - 15 Oct 2015

That is not relevant to my suggested fix.
The fix is needed,

  • what extra work the DOB field needs to do afterwards, it is up to the field itself

e.g. in our case the DOB field can see that

  • a non-empty value was converted by date validation to empty, thus set a message for invalid value, instead of empty value

again that is extra code, that needs to be done extra to the suggested fix

avatar ggppdk
ggppdk - comment - 15 Oct 2015

I am not sure where that code should be,
because i have not looked at it more,

maybe it is not inside the code of the field, maybe inside the JForm class

Possibly,
this is a 3rd issue with JForm, if filtering empties a value then form validation will wrongly report it as empty ?

public function validate($form, $data, $group = null)
{
    // Filter and validate the form data.
    $data = $form->filter($data);
    $return = $form->validate($data, $group);

the validate function does not have access to the original posted data, maybe filtering can return false to indicate invalid field ?

avatar infograf768
infograf768 - comment - 16 Oct 2015

Maybe the Exception could also throw an enqueueMessage?

avatar ggppdk
ggppdk - comment - 20 Oct 2015

Yes, that sounds like a good option

  • invalid date date when filtering code for types 'SERVER_UTC' 'USER_UTC', inside libraries\joomla\form\form.php

should set both

  • set $return to empty and also enqueue a warning

Just the user will get 2 messages:

  • invalid date by the filtering code
  • required field is empty, by the validating code (because filtering set it to empty)

but actually that is another issue ?

  • validating code reports empty field for required fields, if filtering sets a form value to empty string

error messaging in validating code needs to account for this
can we set $return in filtering to false
and validating will not set an error message if
$value===false

avatar ggppdk
ggppdk - comment - 11 Dec 2015

Similar issue: #8646

avatar brianteeman
brianteeman - comment - 28 Jan 2016

Please see and test #8656


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8093.

avatar brianteeman brianteeman - change - 28 Jan 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-01-28 11:46:36
Closed_By brianteeman
avatar brianteeman brianteeman - close - 28 Jan 2016
avatar brianteeman brianteeman - close - 28 Jan 2016
avatar brianteeman
brianteeman - comment - 28 Jan 2016

Closed as we have a PR


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8093.

avatar JasonCromer
JasonCromer - comment - 10 May 2020

Looks like this is happening again, on MacOSX.

Add a Comment

Login with GitHub to post a comment