mirror of
https://github.com/KDE/konsole.git
synced 2026-05-19 03:57:43 -04:00
Abort filter processing if the filter regexp matches the empty string. Fixes filter getting stuck in infinite loop. Use a static const QRegExp for the URL filter regexp since it never changes.
svn path=/branches/work/konsole-split-view/; revision=658740
This commit is contained in:
@@ -345,7 +345,7 @@ QStringList RegExpFilter::HotSpot::capturedTexts() const
|
||||
|
||||
void RegExpFilter::setRegExp(const QRegExp& regExp)
|
||||
{
|
||||
_searchText = QRegExp(regExp);
|
||||
_searchText = regExp;
|
||||
}
|
||||
QRegExp RegExpFilter::regExp() const
|
||||
{
|
||||
@@ -362,8 +362,10 @@ void RegExpFilter::process()
|
||||
|
||||
Q_ASSERT( text );
|
||||
|
||||
// empty regexp does not match
|
||||
if ( _searchText.isEmpty() )
|
||||
// ignore any regular expressions which match an empty string.
|
||||
// otherwise the while loop below will run indefinitely
|
||||
static const QString emptyString("");
|
||||
if ( _searchText.exactMatch(emptyString) )
|
||||
return;
|
||||
|
||||
while(pos >= 0)
|
||||
@@ -394,6 +396,8 @@ void RegExpFilter::process()
|
||||
addHotSpot( spot );
|
||||
pos += _searchText.matchedLength();
|
||||
|
||||
// if matchedLength == 0, the program will get stuck in an infinite loop
|
||||
Q_ASSERT( _searchText.matchedLength() > 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,9 +437,9 @@ UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const
|
||||
{
|
||||
QString url = capturedTexts().first();
|
||||
|
||||
if ( QRegExp(FullUrlRegExp).exactMatch(url) )
|
||||
if ( FullUrlRegExp.exactMatch(url) )
|
||||
return StandardUrl;
|
||||
else if ( QRegExp(EmailAddressRegExp).exactMatch(url) )
|
||||
else if ( EmailAddressRegExp.exactMatch(url) )
|
||||
return Email;
|
||||
else
|
||||
return Unknown;
|
||||
@@ -480,17 +484,18 @@ void UrlFilter::HotSpot::activate(QObject* object)
|
||||
//regexp matches:
|
||||
// full url:
|
||||
// protocolname:// or www. followed by numbers, letters dots and dashes or the '@' character.
|
||||
const QString UrlFilter::FullUrlRegExp("([a-z]+://|www\\.)[a-zA-Z0-9@\\-\\./]+");
|
||||
const QRegExp UrlFilter::FullUrlRegExp("([a-z]+://|www\\.)[a-zA-Z0-9@\\-\\./]+");
|
||||
// email address:
|
||||
// [word chars, dots or dashes]@[word chars, dots or dashes].[word chars]
|
||||
const QString UrlFilter::EmailAddressRegExp("(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+");
|
||||
const QRegExp UrlFilter::EmailAddressRegExp("(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+");
|
||||
|
||||
// matches full url or email address
|
||||
const QRegExp UrlFilter::CompleteUrlRegExp('('+FullUrlRegExp.pattern()+'|'+
|
||||
EmailAddressRegExp.pattern()+')');
|
||||
|
||||
UrlFilter::UrlFilter()
|
||||
{
|
||||
//FIXME - There is a bug where URLs are not identified if they occur at the very
|
||||
//end of the output ( the last characters before any trailing whitespace )
|
||||
|
||||
setRegExp( QRegExp('('+FullUrlRegExp+'|'+EmailAddressRegExp+')') );
|
||||
setRegExp( CompleteUrlRegExp );
|
||||
}
|
||||
UrlFilter::HotSpot::~HotSpot()
|
||||
{
|
||||
|
||||
@@ -211,12 +211,22 @@ public:
|
||||
/** Constructs a new regular expression filter */
|
||||
RegExpFilter();
|
||||
|
||||
/** Sets the regular expression which the filter searches for in blocks of text */
|
||||
/**
|
||||
* Sets the regular expression which the filter searches for in blocks of text.
|
||||
*
|
||||
* Regular expressions which match the empty string are treated as not matching
|
||||
* anything.
|
||||
*/
|
||||
void setRegExp(const QRegExp& text);
|
||||
/** Returns the regular expression which the filter searches for in blocks of text */
|
||||
QRegExp regExp() const;
|
||||
|
||||
/** Reimplemented to search the filter's text buffer for text matching regExp() */
|
||||
/**
|
||||
* Reimplemented to search the filter's text buffer for text matching regExp()
|
||||
*
|
||||
* If regexp matches the empty string, then process() will return immediately
|
||||
* without finding results.
|
||||
*/
|
||||
virtual void process();
|
||||
|
||||
protected:
|
||||
@@ -275,8 +285,11 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
static const QString FullUrlRegExp;
|
||||
static const QString EmailAddressRegExp;
|
||||
static const QRegExp FullUrlRegExp;
|
||||
static const QRegExp EmailAddressRegExp;
|
||||
|
||||
// combined OR of FullUrlRegExp and EmailAddressRegExp
|
||||
static const QRegExp CompleteUrlRegExp;
|
||||
};
|
||||
|
||||
class FilterObject : public QObject
|
||||
|
||||
Reference in New Issue
Block a user