Skip to content

Fix regression that not allow to use a custom filter with subform field#27561

Merged
rdeutz merged 3 commits intojoomla:stagingfrom
Fedik:subform-f-v
Feb 20, 2020
Merged

Fix regression that not allow to use a custom filter with subform field#27561
rdeutz merged 3 commits intojoomla:stagingfrom
Fedik:subform-f-v

Conversation

@Fedik
Copy link
Copy Markdown
Member

@Fedik Fedik commented Jan 18, 2020

Summary of Changes

Fix regression that not allow to use a custom filter with subform field, was introduced by one of previous update.

Testing Instructions

Apply patch, create a subform field , somwhere in CustomHTML module, with custom filter:

<field name="test_fields" type="subform" label="test_fields" 
filter="FooBar::filterTest" multiple="true" min="1">
  <form>
    <field name="test_field" type="text" label="TESTFIELD1"/>
  </form>
</field>

Add custom filter class, somwhere in bottom of plugins/system/debug/debug.php:

class FooBar
{
	static function filterTest($value)
	{
		JFactory::getApplication()
		 ->enqueueMessage('Filter works: ' . json_encode($value));
		return $value;
	}
}

Then create a Custom module in backed, and try save it.
Look for the message you got

Expected result

You should get 2 message:
Filter works: {"test_fields0":{"test_field":""}}
and
Module saved

Actual result

You get 1 message
Module saved
that means the custom filter was ignored

@viocassel
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on da9a1bb


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

1 similar comment
@jwaisner
Copy link
Copy Markdown
Member

I have tested this item ✅ successfully on da9a1bb


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

@Quy Quy removed the PR-staging label Jan 21, 2020
@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 21, 2020

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 21, 2020
@wilsonge
Copy link
Copy Markdown
Contributor

@joomla/security please review this as this addressed a specific vulnerability in the past

$subForm = $field->loadSubForm();

if ($field->multiple)
if ($field->multiple && $value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intention of this change? We might should check whether this is an array right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be an array or an object.

Copy link
Copy Markdown
Member Author

@Fedik Fedik Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intention of this change

if there a no value you will get an php notice while foreach(null as $key => $val)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then let's do is_array here and can we add a comment just explaining it covers an optional subform field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably need is_array() and is_object() in that case. This check also needs to be nested to avoid issues. See #27671.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not make much sense, because if you see whole condition, it still will be validated

if ($field->multiple && $value)
{
foreach ($value as $key => $val)
{
$val = (array) $val;
$valid = $subForm->validate($val);
if ($valid === false)
{
break;
}
}
}
else
{
$valid = $subForm->validate($value);
}

filter already have the same conditions

if ($field->multiple && !empty($value))
{
$return = array();
foreach ($value as $key => $val)
{
$return[$key] = $subForm->filter($val);
}
}
else
{
$return = $subForm->filter($value);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire concept of validating an empty value seems weird to me :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but that what we have ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be validated if you follow #27671. Apply same changes to filter.

@zero-24
Copy link
Copy Markdown
Contributor

zero-24 commented Jan 21, 2020

@joel-lupfer @SniperSister Any additional input here?

@HLeithner HLeithner added this to the Joomla! 3.9.16 milestone Jan 22, 2020
@Quy Quy added the PR-staging label Jan 23, 2020
@richard67
Copy link
Copy Markdown
Member

@joel-lupfer @SniperSister Any additional input here?

@SniperSister
Copy link
Copy Markdown
Contributor

@richard67 fine for me!

@joomla joomla deleted a comment Feb 20, 2020
@rdeutz rdeutz merged commit 914a371 into joomla:staging Feb 20, 2020
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 20, 2020
@Fedik Fedik deleted the subform-f-v branch February 21, 2020 08:40
@wilsonge wilsonge mentioned this pull request Mar 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.