forked from qt-creator/qt-creator
Fix broken list requests in CodePaster.
Pastebin.com-support: Remove header from list data. KDE Paste: Add trailing slash to prevent redirection. Task-number: QTCREATORBUG-9547 Change-Id: If47c4bc64767efb6f1a17db22ff9e0dbee3841bc Reviewed-by: Michael Bruning <michael.bruning@digia.com> Reviewed-by: Robert Loehning <robert.loehning@digia.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -199,7 +199,8 @@ void KdePasteProtocol::list()
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(!m_listReply, return);
|
QTC_ASSERT(!m_listReply, return);
|
||||||
|
|
||||||
QString url = QLatin1String(hostUrlC) + QLatin1String("api/xml/all");
|
// Trailing slash is important to prevent redirection.
|
||||||
|
QString url = QLatin1String(hostUrlC) + QLatin1String("api/xml/all/");
|
||||||
m_listReply = httpGet(url);
|
m_listReply = httpGet(url);
|
||||||
connect(m_listReply, SIGNAL(finished()), this, SLOT(listFinished()));
|
connect(m_listReply, SIGNAL(finished()), this, SLOT(listFinished()));
|
||||||
if (debug)
|
if (debug)
|
||||||
|
@@ -308,12 +308,21 @@ static inline ParseState nextClosingState(ParseState current, const QStringRef &
|
|||||||
return ParseError;
|
return ParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QStringList parseLists(QIODevice *io)
|
static inline QStringList parseLists(QIODevice *io, QString *errorMessage)
|
||||||
{
|
{
|
||||||
enum { maxEntries = 200 }; // Limit the archive, which can grow quite large.
|
enum { maxEntries = 200 }; // Limit the archive, which can grow quite large.
|
||||||
|
|
||||||
QStringList rc;
|
QStringList rc;
|
||||||
QXmlStreamReader reader(io);
|
// Read answer and delete part up to the main table since the input form has
|
||||||
|
// parts that can no longer be parsed using XML parsers (<input type="text" x-webkit-speech />)
|
||||||
|
QByteArray data = io->readAll();
|
||||||
|
const int tablePos = data.indexOf("<table class=\"maintable\" cellspacing=\"0\">");
|
||||||
|
if (tablePos < 0) {
|
||||||
|
*errorMessage = QLatin1String("Could not locate beginning of table.");
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
data.remove(0, tablePos);
|
||||||
|
QXmlStreamReader reader(data);
|
||||||
ParseState state = OutSideTable;
|
ParseState state = OutSideTable;
|
||||||
int tableRow = 0;
|
int tableRow = 0;
|
||||||
int tableColumn = 0;
|
int tableColumn = 0;
|
||||||
@@ -401,6 +410,8 @@ static inline QStringList parseLists(QIODevice *io)
|
|||||||
break;
|
break;
|
||||||
} // switch reader state
|
} // switch reader state
|
||||||
}
|
}
|
||||||
|
if (reader.hasError())
|
||||||
|
*errorMessage = QString::fromLatin1("Error at line %1:%2").arg(reader.lineNumber()).arg(reader.errorString());
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +422,10 @@ void PasteBinDotComProtocol::listFinished()
|
|||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "listFinished: error" << m_listReply->errorString();
|
qDebug() << "listFinished: error" << m_listReply->errorString();
|
||||||
} else {
|
} else {
|
||||||
QStringList list = parseLists(m_listReply);
|
QString errorMessage;
|
||||||
|
const QStringList list = parseLists(m_listReply, &errorMessage);
|
||||||
|
if (list.isEmpty())
|
||||||
|
qWarning().nospace() << "Failed to read list from " << PASTEBIN_BASE << ':' << errorMessage;
|
||||||
emit listDone(name(), list);
|
emit listDone(name(), list);
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << list;
|
qDebug() << list;
|
||||||
|
Reference in New Issue
Block a user