From: Denis Dolzhenko Date: Thu, 27 Jul 2017 08:31:22 +0000 (+0300) Subject: Fix of email validation X-Git-Tag: submit/tizen/20170728.083506^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F57%2F140957%2F3;p=profile%2Fmobile%2Fapps%2Fnative%2Fmessage.git Fix of email validation Change-Id: I96f423fec9ec6292147b92f1cd5d3e0504aff75f Signed-off-by: Denis Dolzhenko --- diff --git a/src/Common/MsgEngine/src/MsgUtils.cpp b/src/Common/MsgEngine/src/MsgUtils.cpp index 72224d0..4ebd43d 100644 --- a/src/Common/MsgEngine/src/MsgUtils.cpp +++ b/src/Common/MsgEngine/src/MsgUtils.cpp @@ -16,6 +16,7 @@ #include "MsgUtils.h" #include "LangUtils.h" +#include "Logger.h" #include #include @@ -28,7 +29,7 @@ namespace { unsigned emailAddrLenMax = 256; const char *delimiters = ",;"; const char *numberRegex = "\\+?([[:digit:]][ *\\(\\)-]*){2,14}[[:digit:]]$"; - const char *emailRegex = "(([[:alnum:]_!#$%&'*+/=?`{|}~^-]+)|(^\"([[:alnum:]_!#$%&'*+/=?`{|}~^-\\(\\)<>\\[\\]:;@,. (\\\\)(\\\")])+\"))+(?:\\.(([[:alnum:]_!#$%&'*+/=?`{|}~^-]+)|(\"([[:alnum:]_!#$%&'*+/=?`{|}~^-\\(\\)<>\\[\\]:;@,. (\\\\)(\\\")])+\")))*@[[:alnum:]-]+(?:\\.[[:alnum:]-]+)*"; + const char *emailRegex = "(?:(?:[^<>()\\[\\].,;:\\s@\"]+(?:\\.[^<>()\\[\\].,;:\\s@\"]+)*)|\".+\")@(?:(?:[^<>()‌​\\[\\].,;:\\s@\"]+\\.)+[^<>()\\[\\].,;:\\s@\"]{2,})"; } TokenizedRecipients MsgUtils::tokenizeRecipients(const std::string &inputText) @@ -62,9 +63,13 @@ bool MsgUtils::isValidNumber(const std::string &address) { if (address.empty()) return false; - - std::regex numTemplate(numberRegex); - return std::regex_match(address, numTemplate); + try { + std::regex numTemplate(numberRegex); + return std::regex_match(address, numTemplate); + } catch (const std::regex_error& e) { + MSG_LOG_ERROR("std::regex_error"); + return false; + } } bool MsgUtils::isValidEmail(const std::string &address) @@ -72,8 +77,13 @@ bool MsgUtils::isValidEmail(const std::string &address) if (address.empty() || address.length() > emailAddrLenMax) return false; - std::regex emailTemplate(emailRegex); - return std::regex_match(address, emailTemplate); + try { + std::regex emailTemplate(emailRegex); + return std::regex_match(address, emailTemplate); + } catch (const std::regex_error& e) { + MSG_LOG_ERROR("std::regex_error"); + return false; + } } bool MsgUtils::isValidAddress(const std::string &address)