From 38d990636ff43e960048dbbeeedd2ae85b87fe38 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Mon, 4 Oct 2010 13:30:25 +0200
Subject: [PATCH] CodePaster[CodePaster]: Allow for fetching complete URLs.

Reviewed-by: Tobias Hunger <qt-info@nokia.com>
Task-number: QTCREATORBUG-2542
---
 src/plugins/cpaster/codepasterprotocol.cpp | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/plugins/cpaster/codepasterprotocol.cpp b/src/plugins/cpaster/codepasterprotocol.cpp
index bc8137abfd8..bd7657656c8 100644
--- a/src/plugins/cpaster/codepasterprotocol.cpp
+++ b/src/plugins/cpaster/codepasterprotocol.cpp
@@ -99,13 +99,24 @@ void CodePasterProtocol::fetch(const QString &id)
     QTC_ASSERT(!m_fetchReply, return; )
 
     QString hostName = m_page->hostName();
-    QString link = "http://";
-    link.append(hostName);
-    link.append("/?format=raw&id=");
-    link.append(id);
+    const QString httpPrefix = "http://";
+    QString link;
+    // Did the user enter a complete URL instead of an id?
+    if (id.startsWith(httpPrefix)) {
+        // Append 'raw' format option
+        link = id;
+        link += QLatin1String("&format=raw");
+        const int idPos = id.lastIndexOf(QLatin1Char('='));
+        m_fetchId = idPos != -1 ? id.mid(idPos + 1) : id;
+    } else {
+        link = httpPrefix;
+        link.append(hostName);
+        link.append("/?format=raw&id=");
+        link.append(id);
+        m_fetchId = id;
+    }
     m_fetchReply = httpGet(link);
     connect(m_fetchReply, SIGNAL(finished()), this, SLOT(fetchFinished()));
-    m_fetchId = id;
 }
 
 void CodePasterProtocol::list()
-- 
GitLab