User tests: Successful: Unsuccessful:
Pull Request resolves # .
Fix the validation logic in the ExistsRule form rule. The main change ensures that if a field is marked as required in the XML definition, empty values are not considered valid, while optional fields can accept empty values.
On Postgres this would lead to a real db error because the unpatched rule runs WHERE id = '' against an integer column.
See also reference in UserIdRule:
joomla-cms/libraries/src/Form/Rule/UserIdRule.php
Lines 50 to 55 in 993ba67
The guard deliberately covers only '' and null as empty. ExistsRule is column-agnostic, exists_column may point at any column, and 0 could be a legitimate stored value (e. g. parent_id, access, level, featured, …).
Treating '0' as "empty" would make the rule silently skip validation for those columns.
This rule is not currently in use in the Core.
Setup
Temporarily edit administrator/components/com_content/forms/article.xml (~line 814) to point an ordinary text field at the rule:
<field
name="urlatext"
type="text"
label="COM_CONTENT_FIELD_URLA_LINK_TEXT_LABEL"
validate="exists"
exists_table="#__content"
exists_column="id"
/>
Go to Content → Articles, note an existing article's ID from the list, then open any article and switch to the Images and Links tab. The field is Link A Text.
| # | Enter in "Link A Text" | Expected with patch | Expected without patch |
|---|---|---|---|
| 1 | (leave empty) → Save | Saves normally | Invalid field: Link A Text ← the bug |
| 2 | An existing article ID, e.g. 1 → Save | Saves normally | Saves normally |
| 3 | 999999 → Save | Invalid field: Link A Text | Invalid field: Link A Text |
Test 1 is the fix. Ttests 2 and 3 confirm the rule still validates as before.
Test 4 - required fields still enforced
Add required="true" to the same field, enter a single space, and save.
<field
name="urlatext"
type="text"
label="COM_CONTENT_FIELD_URLA_LINK_TEXT_LABEL"
required="true"
validate="exists"
exists_table="#__content"
exists_column="id"
/>
Expected: Invalid field: Link A Text in both cases. (Entering nothing at all hits Joomla's generic required check before the rule runs, so the space is what actually exercises the rule's required branch.)
Fields that are not required get a wrong validation result.
Rule can be used with Postgres and works as expected for not required fields.
Please select:
Documentation link for guide.joomla.org:
No documentation changes for guide.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
| Labels |
Added:
bug
PR-5.4-dev
|
||
I have tested this item ✅ successfully on 532bd1b
Thank you!
I have tested this item ✅ successfully on 532bd1b
Thank you!
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48314.