From 605ce133e15e2a5dee68f0cbe437b750caa43a00 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 10 Nov 2013 12:27:05 +0100 Subject: [PATCH] OpenSearchReader: Fixed parsing files with XML declaration --- CHANGELOG | 1 + src/lib/opensearch/opensearchreader.cpp | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8edc04047..3f9e24058 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,7 @@ Version 1.5.0 * fixed: loading plugins with relative paths in portable build * fixed: displaying a lot of RSS feeds in RSS widget in locationbar * fixed: enabling disabled rules in AdBlock now works everytime + * fixed: parsing OpenSearch files with XML declaration Version 1.4.4 * released 1 September 2013 diff --git a/src/lib/opensearch/opensearchreader.cpp b/src/lib/opensearch/opensearchreader.cpp index 86974a6b4..fc71824ef 100644 --- a/src/lib/opensearch/opensearchreader.cpp +++ b/src/lib/opensearch/opensearchreader.cpp @@ -99,16 +99,29 @@ OpenSearchEngine* OpenSearchReader::read() OpenSearchEngine* engine = new OpenSearchEngine(); m_searchXml = device()->peek(1024 * 5); - while (!isStartElement() && !atEnd()) { - readNext(); - } - if (!m_searchXml.contains(QLatin1String("http://a9.com/-/spec/opensearch/1.1/")) && !m_searchXml.contains(QLatin1String("http://www.mozilla.org/2006/browser/search/"))) { raiseError(QObject::tr("The file is not an OpenSearch 1.1 file.")); return engine; } + // It just skips the XML declaration + // The parsing code bellow for some reason doesn't like it -,- + + int index = m_searchXml.indexOf(QLatin1String(" 0) { + int end = m_searchXml.indexOf(QLatin1String("?>"), index); + + if (end > 0) { + device()->read(end + 2); + } + } + + while (!isStartElement() && !atEnd()) { + readNext(); + } + + while (!atEnd()) { readNext();