? ? Success

User tests: Successful: Unsuccessful:

avatar Sophist-UK
Sophist-UK
25 Feb 2018

Form path arrays contain duplicates when they shouldn't.

Current code:

foreach ($new as $path)
{
	if (!in_array($path, $paths))
	{
		array_unshift($paths, trim($path));
	}

	if (!is_dir($path))
	{
		array_unshift($paths, trim($path));
	}
}

Proposed code:

foreach ($new as $path)
{
	$path = trim($path);
	if (!in_array($path, $paths) && is_dir($path))
	{
		array_unshift($paths, $path);
	}
}

Summary of Changes

Path arrays currently have duplicate path in them - this PR removes the code which creates duplicates.

Testing Instructions

$form = new JForm('test');
var_dump($form->addFieldPath('/')); // Exists
var_dump($form->addFieldPath('/directory_doesnt_exist')); // Does not exist

Existing result

Returned array shows / and /directory_doesnt_exist twice.

Fixed result

Returned array shows / once and /directory_doesnt_exist is omitted.

Documentation Changes Required

None.

avatar Sophist-UK Sophist-UK - open - 25 Feb 2018
avatar Sophist-UK Sophist-UK - change - 25 Feb 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 25 Feb 2018
Category Libraries
avatar Sophist-UK Sophist-UK - change - 25 Feb 2018
Labels Added: ?
avatar Sophist-UK Sophist-UK - change - 25 Feb 2018
The description was changed
avatar Sophist-UK Sophist-UK - edited - 25 Feb 2018
avatar Sophist-UK Sophist-UK - change - 25 Feb 2018
The description was changed
avatar Sophist-UK Sophist-UK - edited - 25 Feb 2018
avatar Sophist-UK Sophist-UK - change - 25 Feb 2018
The description was changed
avatar Sophist-UK Sophist-UK - edited - 25 Feb 2018
avatar Quy Quy - test_item - 25 Feb 2018 - Tested successfully
avatar Quy
Quy - comment - 25 Feb 2018

I have tested this item successfully on b57ddc3


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

avatar Anu1601CS Anu1601CS - test_item - 27 Feb 2018 - Tested successfully
avatar Anu1601CS
Anu1601CS - comment - 27 Feb 2018

I have tested this item successfully on b57ddc3


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

avatar Quy Quy - change - 27 Feb 2018
Status Pending Ready to Commit
avatar Quy
Quy - comment - 27 Feb 2018

RTC


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

avatar brianteeman brianteeman - change - 5 Mar 2018
Milestone Added:
avatar mbabker
mbabker - comment - 17 Mar 2018

The unit test failure needs to be addressed before this can be merged.

avatar joomla-cms-bot joomla-cms-bot - change - 17 Mar 2018
Milestone Removed:
avatar mbabker mbabker - change - 17 Mar 2018
Status Ready to Commit Pending
avatar joomla-cms-bot joomla-cms-bot - change - 17 Mar 2018
Category Libraries Libraries Unit Tests
avatar Sophist-UK
Sophist-UK - comment - 17 Mar 2018

Apologies - I had not spotted that. Working on it now.

avatar Sophist-UK Sophist-UK - change - 17 Mar 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 17 Mar 2018
Category Libraries Unit Tests Libraries
avatar Sophist-UK
Sophist-UK - comment - 17 Mar 2018

The tests I did when coding was to discover that the original code resulted in weird arrays on my Joomla system, fix the code and see that the arrays on my real Joomla system were now as expected.

This is what is in these variables:

fieldpaths
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form/_testfields
/home/travis/build/joomla/joomla-cms/libraries/joomla/form/fields
/home/travis/build/joomla/joomla-cms/libraries/src/Form/fields

formpaths
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form
/home/travis/build/joomla/joomla-cms/libraries/src/Form/forms

rulepaths
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form/_testrules
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form
/home/travis/build/joomla/joomla-cms/libraries/src/Form/rules

I have no idea why these strings are in there, nor why field1/2/3 etc. should be in there, nor why my change means they are no longer in there.

I need some help to understand this, and then I can fix the tests.

avatar Sophist-UK
Sophist-UK - comment - 17 Mar 2018

Ok - I found where the paths came from - XML in JFormDataHelper.php.

These are not being added because the directory for e.g. field1 doesn't exist.

It should be easy to make the existing tests work by removing the check that the path is to a directory and allow adding files as well as directories, however I am unclear whether these arrays should be of directories only, or whether we should also include files. So I need a steer on this.

P.S. The tests only test that the paths are added from XML - they do not currently check the correct operation of the addXxxxxPath i.e. that directories are added and files and non-existent paths are not. I will add these tests when I fix this.

avatar Sophist-UK Sophist-UK - change - 25 Mar 2018
Labels Removed: ?
avatar Sophist-UK
Sophist-UK - comment - 25 Mar 2018

This should now be mergable.

avatar viocassel viocassel - test_item - 2 Jul 2019 - Tested successfully
avatar viocassel
viocassel - comment - 2 Jul 2019

I have tested this item successfully on b78f879


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

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 21 Jul 2019

@Quy can you please retest?

avatar SharkyKZ SharkyKZ - test_item - 9 Dec 2019 - Tested successfully
avatar SharkyKZ
SharkyKZ - comment - 9 Dec 2019

I have tested this item successfully on b78f879


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

avatar SharkyKZ SharkyKZ - change - 9 Dec 2019
Status Pending Ready to Commit
avatar SharkyKZ
SharkyKZ - comment - 9 Dec 2019

RTC.


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

avatar SharkyKZ
SharkyKZ - comment - 9 Dec 2019

Though I don't understand why do we add non-existing paths anyways.

avatar infograf768 infograf768 - change - 9 Dec 2019
Labels Added: ?
avatar mbabker
mbabker - comment - 9 Dec 2019

Though I don't understand why do we add non-existing paths anyways.

It doesn't hurt anything to have non-existing paths in the registry as long as at runtime when that registry is used the paths are checked to make sure they exist. Otherwise you're doing a check when adding to the registry and when the registry is used, and that comes with a performance hit because it involves filesystem I/O.

avatar HLeithner HLeithner - close - 11 Dec 2019
avatar HLeithner HLeithner - merge - 11 Dec 2019
avatar HLeithner HLeithner - change - 11 Dec 2019
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-12-11 14:28:11
Closed_By HLeithner
avatar HLeithner
HLeithner - comment - 11 Dec 2019

Finally...

Thank you for your optimization.

avatar Sophist-UK
Sophist-UK - comment - 15 Dec 2019

Wow - submitted on 25 Feb 2018, and merged on 11 December 2019 only 23 months later. Is this a record?

P.S. It was only a small fix, but I am glad to be able to contribute.

Add a Comment

Login with GitHub to post a comment