From a3e9fce98b8beadefd6a80c310a6b7523c775dec Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Fri, 3 Aug 2018 17:45:22 +0200 Subject: [PATCH] TT#40953 Allow all not reserved chars for sip URI Change-Id: I64854564ee519b4865745635349f129530510970 --- lib/NGCP/Panel/Field/URI.pm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/Panel/Field/URI.pm b/lib/NGCP/Panel/Field/URI.pm index 15bcfe03cf..d875248cb9 100644 --- a/lib/NGCP/Panel/Field/URI.pm +++ b/lib/NGCP/Panel/Field/URI.pm @@ -51,11 +51,28 @@ apply( { check => sub { my ( $value, $field ) = @_; + #we will not follow to rfc absolutely, so we will not check headers and uri parameters + #but we will include all allowed characters to username + my $domain_chars = '[:alnum:].+:-';# "+" here is from old code, I didn't remove it + my $unreserved_chars = '-_.!~*\'()'; + # "#" is from dtmf-digit => local-phone-number => telephone-subscriber + # "%" is from escaped + # ":" we will not separate username and password + my $userinfo_unreserved_chars = '&=+$,;?/#%:'; + my ($user, $domain) = split(/\@/, $value); + + #https://metacpan.org/pod/URI#PARSING-URIs-WITH-REGEXP + #my($scheme, $authority, $path, $query, $fragment) = + #$uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|; + my $checked; if ($user && $domain) { - if ( $user =~ m/^(sip:)?[a-zA-Z0-9\+\-\.]*$/ && - $domain =~ m/^[^;\?:][^;\?]*$/ ) { + my ($proto, $user_clean, $domain_clean, $rest); + ($proto, $user_clean) = ($user =~/(sip[s]?:)?(.+?)$/i); + ($domain_clean, $rest) = split(/[^$domain_chars]+/, $domain, 2); + if ( $user_clean =~ m/^[[:alnum:]\Q$unreserved_chars$userinfo_unreserved_chars\E]+$/ && + $domain_clean =~ m/^[$domain_chars]+$/i ) { $checked = $value; } }