User tests: Successful: Unsuccessful:
Pull Request resolves #48500.
In Joomla's URL handling for forms (UrlField), form validation (UrlRule), and form filtering (UrlFilter):
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().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.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:
protected $relative = false;, __get('relative'), __set('relative'), and setup() to UrlField, and uses $this->relative in getLayoutData().relative attribute in UrlRule::test() and UrlFilter::filter().UrlFieldTest.php, UrlFilterTest.php, and updates UrlRuleTest.php.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.phptype="url" and relative="false":<field
name="my_url"
type="url"
label="External URL"
relative="false"
validate="url"
filter="url"
/>$form->getInput('my_url').'/test-path' via $form->validate(['my_url' => '/test-path']).'example.com' via the form filter.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".UrlField renders <input type="url"> when relative="false".UrlRule rejects '/test-path' as invalid when relative="false".UrlFilter prepends http:// when relative="false".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
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries Unit Tests |
| Labels |
Added:
Unit/System Tests
PR-5.4-dev
|
||