diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index b6968a863b..bc04c00672 100644 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -114,11 +114,21 @@ void CChatDlg::AddChatText ( QString strChatText ) // analyze strChatText to check if hyperlink (limit ourselves to http(s)://) but do not // replace the hyperlinks if any HTML code for a hyperlink was found (the user has done the HTML // coding hisself and we should not mess with that) - if ( !strChatText.contains ( QRegExp ( "href\\s*=|src\\s*=" ) ) ) + if ( !strChatText.contains ( QRegularExpression ( "href\\s*=|src\\s*=" ) ) ) { // searches for all occurrences of http(s) and cuts until a space (\S matches any non-white-space // character and the + means that matches the previous element one or more times.) - strChatText.replace ( QRegExp ( "(https?://\\S+)" ), "\\1" ); + // This regex now contains three parts: + // - https?://\\S+ matches as much non-whitespace as possible after the http:// or https://, + // subject to the next two parts, which exclude terminating punctuation + // - (??\\[\\]{}]) is a negative look-behind assertion that disallows the match + // from ending with one of the characters !"'()+,.:;<=>?[]{} + // - (??\\[\\]{}]) is a negative look-behind assertion that disallows the match + // from ending with a ? followed by one of the characters !"'()+,.:;<=>?[]{} + // These last two parts must be separate, as a look-behind assertion must be fixed length. +#define PUNCT_NOEND_URL "[!\"'()+,.:;<=>?\\[\\]{}]" + strChatText.replace ( QRegularExpression ( "(https?://\\S+(?\\1" ); } // add new text in chat window diff --git a/src/util.cpp b/src/util.cpp index cdacd3cb42..ed5dc6a84c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -704,25 +704,28 @@ bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAd // hostname:port // (where addr4or6 is a literal IPv4 or IPv6 address, and addr4 is a literal IPv4 address - bool bLiteralAddr = false; - QRegExp rx1 ( "^\\[([^]]*)\\](?::(\\d+))?$" ); // [addr4or6] or [addr4or6]:port - QRegExp rx2 ( "^([^:]*)(?::(\\d+))?$" ); // addr4 or addr4:port or host or host:port + bool bLiteralAddr = false; + QRegularExpression rx1 ( "^\\[([^]]*)\\](?::(\\d+))?$" ); // [addr4or6] or [addr4or6]:port + QRegularExpression rx2 ( "^([^:]*)(?::(\\d+))?$" ); // addr4 or addr4:port or host or host:port QString strPort; + QRegularExpressionMatch rx1match = rx1.match ( strAddress ); + QRegularExpressionMatch rx2match = rx2.match ( strAddress ); + // parse input address with rx1 and rx2 in turn, capturing address/host and port - if ( rx1.indexIn ( strAddress ) == 0 ) + if ( rx1match.capturedStart() == 0 ) { // literal address within [] - strAddress = rx1.cap ( 1 ); - strPort = rx1.cap ( 2 ); + strAddress = rx1match.captured ( 1 ); + strPort = rx1match.captured ( 2 ); bLiteralAddr = true; // don't allow hostname within [] } - else if ( rx2.indexIn ( strAddress ) == 0 ) + else if ( rx2match.capturedStart() == 0 ) { // hostname or IPv4 address - strAddress = rx2.cap ( 1 ); - strPort = rx2.cap ( 2 ); + strAddress = rx2match.captured ( 1 ); + strPort = rx2match.captured ( 2 ); } else {