Fixed XF\Validator\Url::coerceValue does not apply schema for non-www URLs

DragonByte Tech

Well-known member
Affected version
When using the XF\Validator\Url class to validate URLs, entering a non-www URL does not correctly apply the schema.

Test Cases: works. works. does not, and asks to input a valid URL.

Suggested Fix:
Apply the following below else if (substr(strtolower($value), 0, 4) == 'www.')
            $scheme = parse_url($value, PHP_URL_SCHEME);
            if ($scheme === null)
                /** @noinspection HttpUrlsUsage */
                $value = 'http://' . $value;

I used === because of the following note in the documentation for parse_url: "On seriously malformed URLs, parse_url() may return false."

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.7).

Change log:
Properly coerce URLs that may not begin with "www."
There may be a delay before changes are rolled out to the XenForo Community.