Using a file name clause in advanced search crashed the GUI because of a bad dynamic cast in the history management code

This commit is contained in:
Jean-Francois Dockes
2013-05-12 22:33:37 +02:00
parent 836040168f
commit 7dee82154f
4 changed files with 47 additions and 25 deletions
+8 -5
View File
@@ -315,6 +315,12 @@ public:
m_haveWildCards =
(txt.find_first_of(cstr_minwilds) != std::string::npos);
}
SearchDataClauseSimple(const std::string& txt, SClType tp)
: SearchDataClause(tp), m_text(txt), m_curcl(0)
{
m_haveWildCards =
(txt.find_first_of(cstr_minwilds) != std::string::npos);
}
virtual ~SearchDataClauseSimple()
{
@@ -365,10 +371,10 @@ protected:
* field, especially for file names, because this makes searches for
* "*xx" much faster (no need to scan the whole main index).
*/
class SearchDataClauseFilename : public SearchDataClause {
class SearchDataClauseFilename : public SearchDataClauseSimple {
public:
SearchDataClauseFilename(const std::string& txt)
: SearchDataClause(SCLT_FILENAME), m_text(txt)
: SearchDataClauseSimple(txt, SCLT_FILENAME)
{
// File name searches don't count when looking for wild cards.
m_haveWildCards = false;
@@ -383,9 +389,6 @@ public:
}
virtual bool toNativeQuery(Rcl::Db &, void *);
protected:
std::string m_text;
};
+33 -19
View File
@@ -56,18 +56,20 @@ string SearchData::asXML()
// Clause list
os << "<CL>" << endl;
// List conjunction: default is AND, else print it.
if (m_tp != SCLT_AND)
os << "<CLT>" << tpToString(m_tp) << "</CLT>" << endl;
for (unsigned int i = 0; i < m_query.size(); i++) {
SearchDataClause *c = m_query[i];
if (c->getTp() == SCLT_SUB) {
LOGERR(("SearchData::asXML: can't do subclauses !\n"));
continue;
}
if (c->getexclude())
os << "<NEG/>" << endl;
if (c->getTp() == SCLT_PATH) {
// Keep these apart, for compat with the older history format
// Keep these apart, for compat with the older history format. NEG
// is ignored here, we have 2 different tags instead.
SearchDataClausePath *cl =
dynamic_cast<SearchDataClausePath*>(c);
if (cl->getexclude()) {
@@ -76,24 +78,36 @@ string SearchData::asXML()
os << "<YD>" << base64_encode(cl->gettext()) << "</YD>" << endl;
}
continue;
}
} else {
SearchDataClauseSimple *cl =
dynamic_cast<SearchDataClauseSimple*>(c);
os << "<C>" << endl;
if (cl->getTp() != SCLT_AND) {
os << "<CT>" << tpToString(cl->getTp()) << "</CT>" << endl;
os << "<C>" << endl;
if (c->getexclude())
os << "<NEG/>" << endl;
if (c->getTp() != SCLT_AND) {
os << "<CT>" << tpToString(c->getTp()) << "</CT>" << endl;
}
if (c->getTp() == SCLT_FILENAME) {
SearchDataClauseFilename *cl =
dynamic_cast<SearchDataClauseFilename*>(c);
os << "<T>" << base64_encode(cl->gettext()) << "</T>" << endl;
} else {
SearchDataClauseSimple *cl =
dynamic_cast<SearchDataClauseSimple*>(c);
if (!cl->getfield().empty()) {
os << "<F>" << base64_encode(cl->getfield()) << "</F>" <<
endl;
}
os << "<T>" << base64_encode(cl->gettext()) << "</T>" << endl;
if (cl->getTp() == SCLT_NEAR || cl->getTp() == SCLT_PHRASE) {
SearchDataClauseDist *cld =
dynamic_cast<SearchDataClauseDist*>(cl);
os << "<S>" << cld->getslack() << "</S>" << endl;
}
}
os << "</C>" << endl;
}
if (cl->getTp() != SCLT_FILENAME && !cl->getfield().empty()) {
os << "<F>" << base64_encode(cl->getfield()) << "</F>" << endl;
}
os << "<T>" << base64_encode(cl->gettext()) << "</T>" << endl;
if (cl->getTp() == SCLT_NEAR || cl->getTp() == SCLT_PHRASE) {
SearchDataClauseDist *cld =
dynamic_cast<SearchDataClauseDist*>(cl);
os << "<S>" << cld->getslack() << "</S>" << endl;
}
os << "</C>" << endl;
}
os << "</CL>" << endl;