Expand/augment UrlHelper::isValid() to improve correctness and handle more URL types

Created on 13 August 2008, over 16 years ago
Updated 10 September 2024, 2 months ago

valid_url() only does some very simple syntex checks to verify whether the URL is valid and thus accepts some malformed URLs. Still it does not allow all valid URLs (see e.g. #124492: valid_url() does not support all valid URL characters β†’ ).

Only certain URL schemes are accepted (http, https and ftp), though other schemes may be relevant in various use cases (like this: #214516: Add RTSP to default list of allowed protocols β†’ ).

I tried to expand the function with a number of checks controlled by options.

What do you think - is this totally overkill, or is it worth exploring? The code is still work in progress.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 14 hours ago

Created by

πŸ‡©πŸ‡°Denmark c960657

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Core uses a (modified since this issue was opened) regular expression, not filter_var(), so the issue title here is wrong.

    The two bugs in the issue summary were fixed in the meantime, I think we need an updated issue summary with which valid URLs are not allowed by UrlHelper::isValid() and which valid URLs are rejected. These could then be moved into test coverage and we could go from there. The idea in #24 seems fine but is an API addition rather than a bugfix.

  • πŸ‡¬πŸ‡§United Kingdom catch
Production build 0.71.5 2024