Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcfiala’s picture

Status: Active » Closed (won't fix)

Actually, no patch is needed.

The list of allowed protocols is a Drupal variable - filter_allowed_protocols. Currently you can see it being used around line 1141 of link.module, as such:

$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));

If you change the value of filter_allowed_protocols to include 'tel', then it should work fine. I would suggest setting it as a $conf setting in your settings.php myself, or set it inside of a module update hook.

johnnybgoode’s picture

Issue summary: View changes
FileSize
827 bytes

Hi, It appears that with the current url validation in the link module, in addition to adding 'tel' to the 'filter_allowed_protocols' variable, a patch is needed to support tel: links. A fairly straightforward patch is attached and I can confirm it is working with link-7.x-1.x dev running under drupal 7.34.

johnnybgoode’s picture

Status: Closed (won't fix) » Needs review

Changing issue status for testbot

Status: Needs review » Needs work

The last submitted patch, 2: link.allow-tel-links-1993920-2.patch, failed testing.

johnnybgoode’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
827 bytes

Changing version for testbot

Dragan Eror’s picture

Here is updated patch... (diff made according: branch 7.x-1.x and commit 71cddd958bce9a68a0a4316b2ef6bf3966e1a3e3).

Added 'tel' protocol to $allowed_protocols array.

$allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal', 'tel'));

Created $tel_pattern according international phone number format E 164 (http://en.wikipedia.org/wiki/E.164).

$tel_pattern = '/^tel:\+?[1-9]\d{1,15}$/';

Condition checks for $allowed_protocols and $tel_pattern and returns link as external.

Etroid’s picture

Issue summary: View changes

I do think comment #6 provides the most accurate solution. However, given that the international phone number format E 164 can only have a maximum of 15 digits, shouldn't the pattern be as follows:

$tel_pattern = '/^tel:\+?[1-9]\d{1,14}$/';

The national destination code can only have up to 14 digits with a country code of 1 digit. This gives a total of 15 digits

idebr’s picture

Issue tags: +Needs tests
jsst’s picture

Status: Needs review » Reviewed & tested by the community

Patch works as advertised. Note: you must disable URL validation for the field because that only works for real URLs.

weri’s picture

As Etroid mentioned, the whole number should have a maximum of 15 characters. I updated the patch from Dragan Eror.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: link.allow-tel-links-1993920-10.patch, failed testing.

lwalley’s picture

Without using something like Google's libphonenumber library, validation of phone numbers is going to be difficult. However, I think it would be good to retain the URL validation for the other protocols. So, I've updated the patch from #10 to include a new link type LINK_TEL and adjusted the regex slightly to allow numbers starting with 0, which is common for local numbers in e.g. the United Kingdom. To achieve this, I split the regex into two options, one that allows the value to start with +[1-9] (which I assume was the intention of the original requirement for non-zero number, since I don't think there are any international codes starting with 0, but I could be wrong), and the other that allows the value to start with [0-9]. The value is limited to 15 digits.

I'm sure there are many improvements that can be made to this, but at a minimum this patch allows URL validation to remain on for the link field, and adds some basic tests. Patch and interdiff with #10 attached.

lwalley’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Status: Needs review » Needs work

The last submitted patch, 12: link-allow-tel-links-1993920-12.patch, failed testing.

lwalley’s picture

Failing tests are possibly unrelated. Looks like there is an issue with how link field is being added to node type in the tests. Current tests are adding link field to node type through the UI. Unsure of the original intention for doing it through the UI, i.e. whether it is intended to actually test the UI, or if its just for setup. If just for setup, then could maybe be switched to use field_create_field and field_create_instance e.g. something like how ListFieldUITestCase::createListField does it.

idebr’s picture

@Iwalley all tests for the Link module are currently failing. There is an open issue to fix them: #2843813: Fix failing tests due to missing 'administer fields' permission

lwalley’s picture

Ah, that explains that then, thanks.

dandaman’s picture

A client wanted us to allow the links to certain types of extensions on the end of the link, although in some browsers or OSes these are not fully supported. So I changed the regular expression in the patch to this:

$tel_pattern = '/^tel:(?:\+[1-9]\d{1,14}|\d{2,15})(?:(?:,| w | p )\d{1,14})?(?:;(?:isub=|postd=)\d{1,14})?$/';

I'm not that good at reading these IETF specifications, but it at least supports some common post-phone-number items as specified here: https://tools.ietf.org/html/rfc2806#section-2.2

The patch also worked for us, thanks!

lwalley’s picture

Status: Needs work » Needs review
FileSize
3.54 KB
6.31 KB

Re-roll patch from #12 against link 7.x-1.x.

dqd’s picture

Patch looks good. I would like to read about another reviewer before RTBC. Anyone?

alex_optim’s picture

Works fine for me.

pifagor’s picture

Status: Needs review » Reviewed & tested by the community

  • pifagor committed 26c50e3 on 7.x-1.x authored by lwalley
    Issue #1993920 by lwalley, johnnybgoode, Dragan Eror, weri, idebr,...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.