UrlHelper does not support tel:

Created on 26 September 2015, about 9 years ago
Updated 6 October 2024, 3 months ago

Problem/Motivation

As detected by #2484693: Telephone Link field formatter InvalidArgumentException with 5 digits or fewer in the number β†’ , PHP does not guarantee the parse_url function results for URIs.
The problem is that PHP's parse_url is 'designed' for url's not for URIs.
Because by documentation parse_url:

This function is intended specifically for the purpose of parsing URLs and not URIs.

That can lead to many issues as this function is widely used in the Core as shown in the following table:

The ones which work:

Not OK:

Proposed resolution

We have Drupal\Component\Utility\UrlHelper (URL). We should create a similar UrIHelper (URI) class which is a true RFC 3986 parser.

Note: An external parser can't be used with our current Drupal requirements (PHP 5.6+ or php-intl requirements, both which Drupal doesn't have now)

Remaining tasks

Discuss, Fix PHP, Fix Drupal, Enjoy

User interface changes

None.

API changes

An added URIHelper class.

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component

routing system

Created by

πŸ‡«πŸ‡·France duaelfr Montpellier, France

Live updates comments and jobs are added and updated live.
  • Triaged core major

    There is consensus among core maintainers that this is a major issue. Only core committers should add this tag.

  • 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.

  • πŸ‡©πŸ‡ͺGermany marc.bau

    I see you added ['tel:+1 (555) 666-7777'] what is nice as I'm wondering if spaces and brackets should be url encoded in TelephoneLinkFormatter.

    RFC https://datatracker.ietf.org/doc/html/rfc3966#section-5.1 shows an example where <a href="tel:+1-201-555-0111">(201) 555-0111</a> spaces are removed and brakets become hyphens. This seems not addressed here. But maybe this is a follow up issue for TelephoneLinkFormatter?

  • πŸ‡¦πŸ‡ΊAustralia nigelcunningham Geelong

    When implementing this, please don't forget use cases outside of the USA. In Australia, we have some shorter six digit numbers (132 500, for example) and there are also the emergency service numbers (not necessarily 911 - alternatives I know include 000, 111 and 112.

  • πŸ‡¦πŸ‡ΊAustralia darvanen Sydney, Australia

    #64: The documentation β†’ as such indicates that tel: should be supported and #11 is correct that PHP's native parse_url is not fit for purpose here. I think we need to either revive the custom approach or do another scan to see if there's a library out there now which supports this requirement.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    There shouldnt be any validation of anything after `tel:` to be honest. Theres simply to many localized variants, take a look a look a https://github.com/giggsey/libphonenumber-for-php which is implements the PHP version of the unofficially standard phone number validation and formatting library libphonenumber.

    I think, non-empty-string is the only thing we should be validating against.

    Re this issue as a whole, things would be a hell of a lot easier if we don't consider tel:

  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    Related/potential duplicate that addresses this more broadly: πŸ› Not all URIs are URLs, but UriWidget won't accept non-URL URIs Needs work

  • πŸ‡¦πŸ‡ΊAustralia nigelcunningham Geelong

    I started work on updating the patch in earlier commits for merging, per SMustgrave's comment in #64, but have been asked to move on to other things, so I'm pushing what I've gotten done so far in the hope that maybe it won't go to waste.

Production build 0.71.5 2024