[5.0] Fix ShowOnRule validation with wrong results#41918
[5.0] Fix ShowOnRule validation with wrong results#41918HLeithner merged 12 commits intojoomla:5.0-devfrom
Conversation
|
Also tested: Looks 'pretty' solid to me |
|
I have tested this item ✅ successfully on fbdd6ff This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41918. |
|
PR is ready for tests now, I've just completed the instructions. |
|
@richard67 I tried adding an unit test for this rule: richard67#39 |
|
Unit tests have been added. Thanks @heelc29 . Without this PR: With this PR: Difference = the 15 new tests added here. All tests passing. |
|
It looks like I broke phpcs ... |
@heelc29 Yes, and it seems massive. I assume it's tabs being used for indentation. Will check. |
|
@heelc29 The problems were the line endings. Your file had Windows (CR+LF), but we require Unix (LF). I recommend using an editor which shows this, like e.g. "notepad++". |
@richard67 I use VS Code ... it shows only small in the corner. I will take care to change it to LF |
@heelc29 Can't VS Code be configured to use a custom editor and a custom comparison (diff) tool? If you've ever used notepad++ as editor and BejondCompare as diff tool, you will not want anything else anymore. |
|
I like Beyond Compare and use it daily at work ... its easy to compare complete folders and ZIPs 😀 |
|
@obuisard Could you do a quick test again if it still works, and test with field names which contain dashes in addition? Thanks in advance. |
|
@AndySDH Can values also contain dashes, e.g. |
Yes... |
|
What should also be the behavior when there are just several empty spaces in the field? Right now, it fails the test. |
@obuisard Depending on the field type, the value can be anything, right? So e.g. a text field or editor field can also contain characters which it should not contain because we use them in showon conditions as special characters, e.g. If so, these characters would have to be escaped somehow in the value, otherwise a showon could not be used, and catching this with that kind of validation rule would be hard. So either we restrict showon to a subset of fields where that can not happen,or we revert the PR #41460 completely. |
|
We can't really restrict showon to specific types because then we restrict the showon to core fields only. |
|
Then all we can do is to allow all characters in the value expect of those which we need to recognize the showon rules' parts (":" and "!"). If those characters then appear, showon will be broken so or so, without this PR and with this PR and also without the validation rule at all. |
Yes exactly... |
|
I've created a fix now which allows anything for the field values, so only field names are restricted to alphanumeric characters and dashes, and the showon syntax must be correct, i.e. conditions are separated by |
|
|
@obuisard The testing instructions haven't been updated yet. This value should NOT fail validation as a field value can be "3:21" in a text field (e.g. if it represents the time of the day). |
Yes, totally agree. |
|
I have tested this item ✅ successfully on caa7577 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41918. |
|
I have tested this item ✅ successfully on caa7577 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41918. |
|
Just now I've finished testing instructions (actual result and expected result). Are you sure you've tested all that? |
|
Yes, all is working as expected now, tested all combinations I could think of. |
|
Well, the unit tests do their job, so with the 2 successful human tests I think it can be RTC. |
|
@AndySDH Thanks for testing and pushing me into the right direction. As I am not using fields with showon so often and was not the author of that new validation rule, only tried to fix it, I was not aware that field values can be anything, so it was not really clear to me how wrong the validation rule is without this PR. |
You're welcome! Thanks to you actually for working on this improvement. And to @obuisard as well. |
I have tested the values you added once I saw the new test values. |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41918. |
|
Thx |
* Fix ShowOnRule failing for "not empty" rule * Fix wrong split criteria for "and" and "or" * Allow comma-separated value list * Add missing brackets around "|" expression * Add missing begin and end of string anchors * Remove useless "i" modifier as it is not needed * add unit test * Fix line ending - should be Unix not Windows * A few more unit test cases * Allow dashes in field names * Allow any kind of character in field values --------- Co-authored-by: Christian Heel <66922325+heelc29@users.noreply.github.com>


Pull Request for Issue #41788 .
Summary of Changes
The PR currently fixes the issue linked above, but in addition it fixes a general conceptional error with the validation rule added by PR #41460 :
:or!:which separate the field name from the value in showon rules. This was completely broken with PR [5.0] [com_fields] Showon Attribute doesn't accept correct syntax on Joomla 5 #41788 . This PR here fixes that.Finally, it adds unit tests for the ShowOnRule validation rule, thanks @heelc29 for these.
Testing Instructions
(empty value)
box:value1box::box:!box:3:21box:#@\[](the last one is a space)box!:value1box!:box:value1[OR]square:value1box:value1[AND]square:value1box:value1[OR]square!:value1box:value1[AND]square!:value1box:value1[AND]square:value1,value2box:value1[AND]square!:value1,value2box:value1[AND]square!:value1,value2[OR]square!:value1box:value1,value2[AND]square:value1box:value1[AND]square!:value1:value2box-test-1:value1box-test-1!:value1box-test-1!:box-test-1:3:21box:value1[AND]square-test-1!:value1:value2box:value1[OR]square-test-1:value1box:value1[OR]square-test-1!:value1box[AND]box:value3[OR]square:2:3[AND][OR]box@abc:value1box_abc:value1box!abc:value1In addition, check the Drone logs for the unit tests without and with this PR, or run the unit tests yourself using
./libraries/vendor/bin/phpunit --testsuite Unit, and compare the results.Actual result BEFORE applying this Pull Request
The following rules fail validation, but they should pass:
box::box:!box:#@\[](the last one is a space)box!:box-test-1!:The following rules pass validation, but they should fail:
[AND]box:value3[OR]square:2:3box@abc:value1box_abc:value1box!abc:value1Expected result AFTER applying this Pull Request
The following rules are validated with success:
(empty value)
box:value1box::box:!box:3:21box:#@\[](the last one is a space)box!:value1box!:box:value1[OR]square:value1box:value1[AND]square:value1box:value1[OR]square!:value1box:value1[AND]square!:value1box:value1[AND]square:value1,value2box:value1[AND]square!:value1,value2box:value1[AND]square!:value1,value2[OR]square!:value1box:value1,value2[AND]square:value1box:value1[AND]square!:value1:value2box-test-1:value1box-test-1!:value1box-test-1!:box-test-1:3:21box:value1[AND]square-test-1!:value1:value2box:value1[OR]square-test-1:value1box:value1[OR]square-test-1!:value1The following rules fail validation:
box[AND]box:value3[OR]square:2:3[AND][OR]box@abc:value1box_abc:value1box!abc:value1The new unit tests run with success.
Link to documentations
Please select:
No documentation changes for docs.joomla.org needed
No documentation changes for manual.joomla.org needed