Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293828

Add support for additional protocols in Link field definition

$
0
0

Problem/Motivation

The link module only validates http and https, but not other scheme names such as git or ftp.

In Drupal 7, the validation can be turned off, thereby allowing the input of other scheme names. D7 sites could use this to use other scheme names, which will then not be valid in D8 any more.

Even better would be a option in the field configuration to set which scheme names are valid for this field.

Steps to reproduce

NA

Proposed resolution

Allow custom protocols in each link field configuration.

Remaining tasks

  1. Add field configuration for allowing custom protocols. Done.
  2. Ensure field validation included the custom protocols in the whitelist. Done.
  3. Add post update hook to add the new setting to all existing fields. Done.
  4. Add tests. Done.

User interface changes

A new text field added to the Link field configuration form, empty by default, that accepts a comma-separated list of protocols that will be allowed in addition to the hard-coded ones.

API changes

+++ b/core/lib/Drupal/Component/Utility/UrlHelper.php
@@ -209,11 +209,13 @@ public static function encodePath($path) {
-  public static function isExternal($path) {
+  public static function isExternal($path, $protocol_whitelist = []) {
+++ b/core/lib/Drupal/Component/Utility/UrlHelper.php
@@ -353,8 +357,8 @@ public static function setAllowedProtocols(array $protocols = []) {
-  public static function stripDangerousProtocols($uri) {
+  public static function stripDangerousProtocols($uri, $whitelist = []) {
+++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php
@@ -40,6 +40,8 @@ interface UnroutedUrlAssemblerInterface {
+   *   - 'protocol_whitelist': An explicit whitelist of protocols to be allowed
+   *     in addition to those traditionally allowed. Defaults to an empty array.

This adds a new option to the $options array.

Data model changes

Added to the Link field configuration schema:

+++ b/core/modules/link/config/schema/link.schema.yml
@@ -49,6 +49,9 @@ field.field_settings.link:
+    protocol_whitelist:
+      type: string
+      label: 'Protocol whitelist'

Viewing all articles
Browse latest Browse all 293828

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>