? ? Success

User tests: Successful: Unsuccessful:

avatar Harmageddon
Harmageddon
6 May 2019

As far as I see, #12414 seems to have broken the form validation for some fields (except those components which do their own validation after the form validation, like com_users). Please check and inform me if I'm mistaken.

Summary of Changes

The method FormField::validate checks whether the return value of FormRule::test is false and handles errors only in this particular case, returning a simple true for all other cases. The problem here is that FormRule::test might also return an Exception on failure, which doesn't evaluate to false.
A quick glance through the different validation rules shows that this is the case for EmailRule and under some circumstances maybe also for NotequalsRule.

I suppose that this bug can be solved by not naively returning true, but the very result of the validation instead. Of course, another method would be to unify the way we want to treat validation errors by deciding on either returning booleans, returning exceptions or throwing exceptions.

Testing Instructions

  • Navigate to a form that has an email field using server-side validation.
    The error doesn't really occur for creating/editing a user (it occurs, but is only visible in the different styling of the error message), because com_users does another validation when saving. I tested it with the "From Email" field in the global configuration under "Server - Mail Settings".
  • Enter an invalid value like "test".
  • Save / submit the form.

Expected result

The form should not be saved and return an error.

Actual result

The form is saved.

Please also test that valid form submissions are still valid!

avatar Harmageddon Harmageddon - open - 6 May 2019
avatar Harmageddon Harmageddon - change - 6 May 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 6 May 2019
Category Libraries
avatar Fedik
Fedik - comment - 6 May 2019

hm, maybe something else are broken?
because old behavior also has return true; https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Form/Form.php#L2148

or it was always broken :neckbeard:

avatar Fedik
Fedik - comment - 6 May 2019

okay, I see,
old had:

$valid = $rule->test($element, $value, $group, $input, $this);
// Check for an error in the validation test.
if ($valid instanceof \Exception)
{
	return $valid;
}

and new:

try
{
	// Run the field validation rule test.
	$valid = $rule->test($this->element, $value, $group, $input, $this->form);
}
catch (\Exception $e)
{
	return $e;
}

so now it ignores if $valid are Exception.

The patch are good.

avatar SniperSister SniperSister - change - 6 May 2019
Labels Added: ?
avatar Harmageddon Harmageddon - change - 7 May 2019
The description was changed
avatar Harmageddon Harmageddon - edited - 7 May 2019
avatar nadjak77 nadjak77 - test_item - 19 Oct 2019 - Tested successfully
avatar nadjak77
nadjak77 - comment - 19 Oct 2019

I have tested this item successfully on 7af366c

works as descriped


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

avatar euismod2336 euismod2336 - test_item - 19 Oct 2019 - Tested successfully
avatar euismod2336
euismod2336 - comment - 19 Oct 2019

I have tested this item successfully on 7af366c

works as advertised


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

avatar alikon alikon - change - 20 Oct 2019
Status Pending Ready to Commit
avatar alikon
alikon - comment - 20 Oct 2019

RTC


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

avatar wilsonge wilsonge - close - 3 Nov 2019
avatar wilsonge wilsonge - merge - 3 Nov 2019
avatar wilsonge wilsonge - change - 3 Nov 2019
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-11-03 00:44:20
Closed_By wilsonge
Labels Added: ?
avatar wilsonge
wilsonge - comment - 3 Nov 2019

Thanks!

Add a Comment

Login with GitHub to post a comment