Problem/Motivation

Drupal's URL form element uses UrlHelper::isValid() to validate absolute URLs. The Link field follows a different path. Its widget converts user input to a URI, and its field constraints check whether Drupal can construct a URL from that URI, whether the field accepts external links, and whether the site allows the protocol. An external HTTP(S) URL can therefore pass link field validation even when the URL form element rejects its syntax.

Link fields already accept internationalized hostnames and support schemes such as mailto:. Using UrlHelper::isValid($uri, TRUE) unconditionally today would reject valid links that editors can currently save.

Proposed resolution

Use UrlHelper::isValid() for external URL syntax validation at the field level so that the same rules apply when validating a link through the widget or programmatically.

Keep the site's allowed-protocol check. A syntactically valid URL may still use a protocol the site disallows. Preserve support for internal paths, entity links, and special values such as <nolink>.

Remaining tasks

Postponed on:

Add a regression test for a malformed external URL currently accepted by a link field. Cover valid Unicode and Punycode hostnames, an allowed non-HTTP scheme, and a disallowed scheme. Determine the impact on existing field values when an entity is edited and validated again.

User interface changes

Link fields display a validation error for malformed external URLs that previously passed validation.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

Link fields now use the same syntax validation as URL form elements for external URLs.

Comments

pancho created an issue. See original summary.

pancho’s picture

Status: Active » Postponed
dcam’s picture

Status: Postponed » Closed (duplicate)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.