Html entity handling improved. Fixed a bug in source that caused segmentation fault...
[jenirok] / src / common / source.cpp
index 49fc999..a978b45 100644 (file)
@@ -86,7 +86,7 @@ void Source::getSources(QList<SourceDetails>& list)
 }
 
 Source::Source(QObject* parent): QObject(parent),
-maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(false),
+maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(true),
 error_(NO_ERROR), loggedIn_(false)
 {
     connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
@@ -366,6 +366,26 @@ QString& Source::htmlEntityDecode(QString& string)
         string = string.replace("&" + entities[i] + ";", QChar(entityValues[i]));
     }
 
+    static QRegExp entityCleaner("&#([0-9]{1,3});");
+    entityCleaner.setMinimal(true);
+
+    int pos = 0;
+
+    while((pos = entityCleaner.indexIn(string, pos)) != -1)
+    {
+        QString match = entityCleaner.cap(1);
+
+        int value = match.toInt();
+
+        if(value >= 1 && value <= 255)
+        {
+            string = string.replace(pos, match.length() + 3, QChar(value));
+        }
+
+        pos += entityCleaner.matchedLength();
+    }
+
+
    return string;
 }