fnmatch() errors encountered with charset conversion errors on file names were treated as matches

This commit is contained in:
Jean-Francois Dockes 2013-03-27 15:44:24 +01:00
parent e7eafe4ab4
commit 60b9845b83
4 changed files with 39 additions and 12 deletions

View file

@ -168,10 +168,10 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
stripped = o_index_stripchars;
#endif
LOGDEB(("Db::TermMatch: typ %s diacsens %d casesens %d lang [%s] term [%s] "
"max %d field [%s] stripped %d\n",
LOGDEB0(("Db::TermMatch: typ %s diacsens %d casesens %d lang [%s] term [%s]"
" max %d field [%s] stripped %d init res.size %u\n",
tmtptostr(matchtyp), diac_sensitive, case_sensitive, lang.c_str(),
_term.c_str(), max, field.c_str(), stripped));
_term.c_str(), max, field.c_str(), stripped, res.entries.size()));
// If index is stripped, no case or diac expansion can be needed:
// for the processing inside this routine, everything looks like
@ -224,7 +224,7 @@ bool Db::termMatch(int typ_sens, const string &lang, const string &_term,
it != exp.end(); it++) {
idxTermMatch(ET_NONE, "", *it, res, max, field);
}
// And also expand the original expresionn against the
// And also expand the original expression against the
// main index: for the common case where the expression
// had no case/diac expansion (no entry in the exp db if
// the original term is lowercase and without accents).
@ -320,6 +320,10 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root,
TermMatchResult& res, int max, const string& field)
{
int typ = matchTypeTp(typ_sens);
LOGDEB1(("Db::idxTermMatch: typ %s lang [%s] term [%s] "
"max %d field [%s] init res.size %u\n",
tmtptostr(typ), lang.c_str(), root.c_str(),
max, field.c_str(), res.entries.size()));
#ifndef RCL_INDEX_STRIPCHARS
if (typ == ET_STEM) {
@ -380,6 +384,10 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root,
if (matcher.isNotNull()) {
es = matcher->baseprefixlen();
}
// Initial section: the part of the prefix+expr before the
// first wildcard character. We only scan the part of the
// index where this matches
string is;
switch (es) {
case string::npos: is = prefix + root; break;
@ -395,14 +403,23 @@ bool Db::idxTermMatch(int typ_sens, const string &lang, const string &root,
it.skip_to(is.c_str());
for (int rcnt = 0; it != xdb.allterms_end(); it++) {
// If we're beyond the terms matching the initial
// string, end
// section, end
if (!is.empty() && (*it).find(is) != 0)
break;
// Else try to match the term. The matcher content
// is without prefix, so we remove this if any. We
// just checked that the index term did begin with
// the prefix.
string term;
if (!prefix.empty())
if (!prefix.empty()) {
term = (*it).substr(prefix.length());
else
} else {
if (has_prefix(*it)) {
continue;
}
term = *it;
}
if (matcher.isNotNull() && !matcher->match(term))
continue;

View file

@ -622,7 +622,7 @@ bool SearchDataClauseSimple::expandTerm(Rcl::Db &db,
if (noexpansion) {
oexp.push_back(prefix + term);
m_hldata.terms[term] = m_hldata.uterms.size() - 1;
LOGDEB(("ExpandTerm: final: %s\n", stringsToString(oexp).c_str()));
LOGDEB(("ExpandTerm: noexpansion: final: %s\n", stringsToString(oexp).c_str()));
return true;
}

View file

@ -222,7 +222,7 @@ bool XapComputableSynFamMember::synKeyExpand(StrMatcher* inexp,
if (filter_exp.isNotNull()) {
string term1 = (*filtertrans)(term);
LOGDEB2((" Testing [%s] against [%s]\n",
term1.c_str(), filter_exp.c_str()));
term1.c_str(), filter_exp->exp().c_str()));
if (!filter_exp->match(term1)) {
continue;
}

View file

@ -26,12 +26,22 @@
using std::string;
#include "cstr.h"
#include "debuglog.h"
#include "strmatcher.h"
bool StrWildMatcher::match(const string& val) const
{
return fnmatch(m_sexp.c_str(), val.c_str(), 0) != FNM_NOMATCH;
LOGDEB2(("StrWildMatcher::match: [%s] against [%s]\n",
m_sexp.c_str(), val.c_str()));
int ret = fnmatch(m_sexp.c_str(), val.c_str(), FNM_NOESCAPE);
switch (ret) {
case 0: return true;
case FNM_NOMATCH: return false;
default:
LOGDEB0(("StrWildMatcher::match error: [%s] against [%s]\n",
m_sexp.c_str(), val.c_str()));
return false;
}
}
string::size_type StrWildMatcher::baseprefixlen() const