fix(commands): Improve phone number input validation of OCC commands - #17173
Conversation
| // And matches a local number or dial-through | ||
| && preg_match('/^[0-9]{1,20}$/', $phoneNumber) | ||
| ) { | ||
| return $phoneNumber; |
There was a problem hiding this comment.
@fancycode is the free pass for local numbers okay? Or should e.g. 0711 be replaced with 49711 if DE is specified as default phone prefix. I assume it would be bad, as it would prevent specifying 0711β¦ even if that would be what your SIP gate receives
There was a problem hiding this comment.
An internal extension should never start with a 0, so you could add the international prefix if configured (i.e. 071112345 becomes +4971112345) or just reject such numbers.
To make things worse, the 00 prefix for international numbers is only if calling from Germany to another country. For example calling from the US to another country needs 011 as prefix, from Australia it's 0011. See https://en.wikipedia.org/wiki/List_of_international_call_prefixes for other prefixes. So replacing 00 with a + will fail for Australian people trying to configure 00114971112345 as German number in Stuttgart.
You could try to guess based on the default phone prefix what the user might try to do, but maybe the easiest is to simply reject numbers that start with a 0.
There was a problem hiding this comment.
So the only thing I can do is look for a leading 0 or +
try to convert to standard and strip of the +, if there was no + return it's invalid?
There was a problem hiding this comment.
Yes, I think that would be the best, though libphonenumber supports detecting valid numbers with a leading 0 if a country is configured.
Some testcases (assuming DE is configured as default phone country):
4971112345 -> 4971112345
+4971112345 -> 4971112345
4911223344 -> reject (should be detected to be invalid by libphonenumber)
+4911223344 -> reject (should be detected to be invalid by libphonenumber)
004971112345 -> 4971112345 (should be detected to be valid by libphonenumber, would be invalid if Australia is configured as default phone country)
00112345678901 -> 112345678901 (looks like a valid US number for libphonenumber)
00111122233344 -> reject (not a valid US number)
071112345 -> 4971112345 (0711 is a German local prefix)
011223344 -> reject (01122 is not a valid German local prefix)
3001 -> 3001 (might be an extension in a local PBX)
03001 -> reject (030 could be Berlin but 01 is too short)
There was a problem hiding this comment.
00112345678901 -> 112345678901 (looks like a valid US number for libphonenumber)
This one is striping off a leading 1, but sure why. But the normalizing returns: +12345678901 so only a single 1 not 2 as you posted.
ba6e346 to
9111c65
Compare
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
9111c65 to
062bacc
Compare
|
/backport to stable33 |
|
/backport to stable32 |
βοΈ Resolves
π οΈ API Checklist
π§ Tasks
π Checklist
docs/has been updated or is not required