Needs review
Project:
Phone
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 May 2012 at 22:19 UTC
Updated:
14 May 2017 at 17:31 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
morelight commentedexample 2: If i have specified +46 as default and someone types their phonenumber like: 08-123 123 it gets converted to +46 123 123
Comment #2
mgiffordHow is this issue is different from #1605128: Austrian and Romanian phone number missing other than that this is a different country? Any reason not to mark this a duplicate? Figure out how to fix it and roll it out on all regions?
Comment #3
seanrmgifford, that issue is quite clearly unrelated if you read the two threads. That one is rejecting numbers outright, this one is literally stripping out part of the number while still accepting the submission.
At any rate, what is happening here is if you set the field settings to accept any international number, the module doesn't use the detected country code of the number in phone_field_presave() but instead uses in, and then formats the number before saving (WHY? we should ALWAYS preserve input date and format only on output!). That formats using int instead of the actual country, hitting format_int_phone_number() which does this:
This strikes me as very arbitrary and a bad idea. First off, let's preserve input data and only format on output. Second, why aren't we letting the individual country formatters handle the formatting? If it's a question of showing vs not showing the country codes, I get that, but then let's pull off the country code in format_int_phone_number(), then pass the rest of the number to its correct formatter, then re-attach and send to the browser.
So there are two issues here obviously:
#1 can go in a separate issue, I suppose (which I will do), but #2 is definitely the root cause of the specific bug in this thread and we should address that here. I'll work on a patch today.
Marking as Major since this is violating data integrity (due in part to #1).
Comment #4
mgiffordThanks for the clarification @seanr
Comment #5
seanrThis patch adds a check to see if the country code is supported and if so, runs it through the appropriate formatter function.
Comment #6
roderikSo... the existing code just strips area codes 00 AND 7 / 8 / 07 / 08 at a whim, eh?
Judging this http://www.allareacodes.com/international_dialing_codes.htm, this is only for countries inside the '7' dialing area (ru), which will never execute that code - because there's a .ru.inc file.
So, shall we get rid of the arbitrary stuff at the same time?
Comment #7
roderikOne note, though: you must not apply this patch unless you already applied #2186331: phone_field_presave() calls format_phone_number(), breaking input data integrity. Otherwise your phone numbers may be saved without a country code! (Depending on your field-instance settings.)
Comment #8
klokie commentedThe regular expression wasn't working for any Swedish phone numbers that I tried, so I simplified and replaced it. Comments welcome.