Only prepend hedgewars.org if the url is relative
authorunc0rr
Sun, 04 Sep 2011 20:51:54 +0400 (2011-09-04)
changeset 5768 852ba8f5685c
parent 5767 e00c0a56e80e
child 5769 09aca6e1317a
Only prepend hedgewars.org if the url is relative
QTfrontend/pagedata.cpp
--- a/QTfrontend/pagedata.cpp	Sun Sep 04 12:47:10 2011 -0400
+++ b/QTfrontend/pagedata.cpp	Sun Sep 04 20:51:54 2011 +0400
@@ -56,12 +56,18 @@
 
 void PageDataDownload::request(const QUrl &url)
 {
+    QUrl finalUrl;
+    if(url.host().isEmpty())
+        finalUrl = QUrl("http://www.hedgewars.org" + url.path());
+    else
+        finalUrl = url;
+
     if(url.path().endsWith(".zip"))
     {
         qWarning() << "Download Request" << url.toString();
         QString fileName = QFileInfo(url.toString()).fileName();
 
-        QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.path()));
+        QNetworkRequest newRequest(finalUrl);
         newRequest.setAttribute(QNetworkRequest::User, fileName);
 
         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
@@ -76,7 +82,7 @@
     {
         qWarning() << "Page Request" << url.toString();
 
-        QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + url.path()));
+        QNetworkRequest newRequest(finalUrl);
 
         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
         QNetworkReply *reply = manager->get(newRequest);
@@ -92,8 +98,13 @@
     if(reply)
     {
         QString html = QString::fromUtf8(reply->readAll());
-        html.remove(0,html.indexOf("<!-- BEGIN -->"));
-        html.truncate(html.indexOf("<!-- END -->"));
+        int begin = html.indexOf("<!-- BEGIN -->");
+        int end = html.indexOf("<!-- END -->");
+        if(begin != -1 && begin < end)
+        {
+            html.truncate(end);
+            html.remove(0, begin);
+        }
         web->setHtml(html);
     }
 }