Unit/System Tests PR-5.4-dev Pending

User tests: Successful: Unsuccessful:

avatar bhuvan-somisetty
bhuvan-somisetty
25 Sep 2026

Pull Request resolves #48500.

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

In Joomla's URL handling for forms (UrlField), form validation (UrlRule), and form filtering (UrlFilter):

  1. UrlField::getLayoutData() directly evaluated $this->element['relative'] as a SimpleXMLElement object. In PHP, any non-empty SimpleXMLElement object evaluates to true in a boolean context, causing relative="false" to render as <input type="text"> instead of <input type="url">. Additionally, UrlField lacked a relative property, property getters/setters (__get / __set), and XML attribute parsing in setup().
  2. UrlRule::test() evaluated !$element['relative'] directly as a SimpleXMLElement object, causing !$element['relative'] to evaluate to false when relative="false". This allowed scheme-less relative paths (such as /my-path) to pass validation when relative URLs were explicitly disallowed.
  3. UrlFilter::filter() evaluated !$element['relative'] and $element['relative'] directly as a SimpleXMLElement object, causing relative="false" to be treated as an internal relative URL and prepending the site root path instead of prepending the default external protocol (http://).

This PR:

  1. Adds protected $relative = false;, __get('relative'), __set('relative'), and setup() to UrlField, and uses $this->relative in getLayoutData().
  2. Properly casts and evaluates the relative attribute in UrlRule::test() and UrlFilter::filter().
  3. Adds comprehensive unit tests in UrlFieldTest.php, UrlFilterTest.php, and updates UrlRuleTest.php.

Testing Instructions

1. Automated Tests

Run PHPUnit tests:

libraries/vendor/bin/phpunit tests/Unit/Libraries/Cms/Form/Field/UrlFieldTest.php
libraries/vendor/bin/phpunit tests/Unit/Libraries/Cms/Form/Rule/UrlRuleTest.php
libraries/vendor/bin/phpunit tests/Unit/Libraries/Cms/Form/Filter/UrlFilterTest.php

2. Manual Test via Form Field

  1. Define a form XML with type="url" and relative="false":
<field
    name="my_url"
    type="url"
    label="External URL"
    relative="false"
    validate="url"
    filter="url"
/>
  1. Render the field via $form->getInput('my_url').
  2. Validate a relative value '/test-path' via $form->validate(['my_url' => '/test-path']).
  3. Filter a scheme-less value 'example.com' via the form filter.

Actual result BEFORE applying this Pull Request

  • UrlField renders <input type="text"> (instead of <input type="url">) when relative="false".
  • UrlRule accepts '/test-path' as valid when relative="false".
  • UrlFilter prepends the site root path instead of http:// when relative="false".

Expected result AFTER applying this Pull Request

  • UrlField renders <input type="url"> when relative="false".
  • UrlRule rejects '/test-path' as invalid when relative="false".
  • UrlFilter prepends http:// when relative="false".

Link to documentations

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

Signed-off-by: bhuvan-somisetty somisettybhuvan5@gmail.com

avatar bhuvan-somisetty bhuvan-somisetty - open - 25 Sep 2026
avatar bhuvan-somisetty bhuvan-somisetty - change - 25 Sep 2026
Status New ⇒ Pending
avatar joomla-cms-bot joomla-cms-bot - change - 25 Sep 2026
Category ⇒ Libraries Unit Tests
avatar bhuvan-somisetty bhuvan-somisetty - change - 25 Sep 2026
Labels Added: Unit/System Tests PR-5.4-dev

Add a Comment

Login with GitHub to post a comment