Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/chatdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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+)" ), "<a href=\"\\1\">\\1</a>" );
// 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+(?<!" PUNCT_NOEND_URL ")(?<!\\?" PUNCT_NOEND_URL "))" ),
"<a href=\"\\1\">\\1</a>" );
}

// add new text in chat window
Expand Down
21 changes: 12 additions & 9 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down