Problem/Motivation

The “Convert URLs into links” text filter currently hardcodes http:// when converting URLs without an explicitly specified protocol, such as "www.example.com".

This results in generated links like:
<a href="http://www.example.com">www.example.com</a>

For sites that are served exclusively over HTTPS, this is undesirable. It can cause unnecessary redirects, mixed-content-related issues in some contexts, and inconsistent use of secure URLs.
The filter should allow site administrators to choose whether URLs without a protocol are converted using http:// or https://.
URLs that already include a protocol, such as http://example.com or https://example.com, must remain unchanged.

I'm a bit surprised that there isn't a task like this in the issue queue yet.

Steps to reproduce

  1. Enable the “Convert URLs into links” filter for a text format.
  2. Enter text containing a URL without a protocol, for example: "Visit www.example.com"
  3. Render the text using the configured text format.
  4. Inspect the generated HTML.

Actual result
The URL is converted to:
<a href="http://www.example.com">www.example.com</a>

Expected result
The filter should provide a configuration option that allows the administrator to generate either:
<a href="http://www.example.com">www.example.com</a>
or:
<a href="https://www.example.com">www.example.com</a>

The default should remain http:// for backward compatibility.

Proposed resolution

Add a boolean setting to the “Convert URLs into links” filter configuration, for example:
filter_url_secure_links: false

When enabled, the filter should use https:// for URLs without an explicitly specified protocol.

The setting should:

  • default to FALSE
  • affect only URLs without a protocol, such as www.example.com
  • leave explicit http:// and https:// URLs unchanged

The configuration form could use a label such as:
Use https:// for links without a protocol

Remaining tasks

User interface changes

The “Convert URLs into links” filter configuration form will gain a checkbox allowing administrators to select whether protocol-less URLs use http:// or https://.

Introduced terminology

API changes

Data model changes

Release notes snippet

The “Convert URLs into links” filter can now be configured to generate https:// links for URLs without an explicitly specified protocol.

Issue fork drupal-3615838

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mrshowerman created an issue. See original summary.

mrshowerman’s picture

Assigned: mrshowerman » Unassigned
Status: Active » Needs review
smustgrave’s picture

Probably needs sub-maintainer approval, not sure if it hits the 80% use case for most users and wonder if contrib would be better? But will let maintainers decide.

smustgrave’s picture