fix check when the second argument contains operator-characters

master
Marc Wäckerlin 5 years ago
parent 6d81df1678
commit bedf4ca32a
  1. 2
      configure.ac
  2. 21
      src/commands.hxx
  3. 3
      src/exceptions.hxx

@ -19,7 +19,7 @@ AM_INIT_AUTOMAKE([1.9 tar-pax])
AX_INIT_STANDARD_PROJECT AX_INIT_STANDARD_PROJECT
# requirements, uncomment, what you need: # requirements, uncomment, what you need:
AX_USE_CXX AX_USE_CXX_11
#AX_USE_LIBTOOL #AX_USE_LIBTOOL
AX_USE_SCRIPTS AX_USE_SCRIPTS
AX_USE_DOXYGEN AX_USE_DOXYGEN

@ -32,6 +32,8 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <cassert> #include <cassert>
#include <istream>
#include <ostream>
#include <xml-cxx/xml.hxx> #include <xml-cxx/xml.hxx>
#include <mrw/stdext.hxx> #include <mrw/stdext.hxx>
@ -210,24 +212,27 @@ class Command: public QObject {
} }
QStringList quotedStrings(QString value, QStringList quotedStrings(QString value,
QString delimiter = " ", QString delimiter = " ",
bool keepDelimiters = false) const { bool keepDelimiters = false,
unsigned int max = 0) const {
QStringList res; QStringList res;
QString quot("'\""); QString quot("'\"");
unsigned int found(0);
while (value=value.trimmed(), value.size()) { while (value=value.trimmed(), value.size()) {
QRegularExpression re; QRegularExpression re;
int start(0); int start(0);
if (quot.contains(value[0])) { if (quot.contains(value[0])) {
re = QRegularExpression(value[0]+" *(("+delimiter+" *)|$)"); re = QRegularExpression(value[0]+" *((("+delimiter+") *)|$)");
start = 1; start = 1;
} else { } else {
re = QRegularExpression("( *"+delimiter+" *)|$"); re = QRegularExpression(" *((("+delimiter+") *)|$)");
} }
int pos(value.indexOf(re, start)); int pos(value.indexOf(re, start));
if (pos<start) throw BadArgument("quote missmatch in "+value); if (pos<start) throw BadArgument("quote missmatch in "+value);
QRegularExpressionMatch m(re.match(value, start)); QRegularExpressionMatch m(re.match(value, start));
res += value.mid(start, m.capturedStart()-start); res += value.mid(start, m.capturedStart()-start);
value.remove(0, m.capturedEnd()); value.remove(0, m.capturedEnd());
if (keepDelimiters && m.capturedLength()) res+=m.captured().mid(start).trimmed(); if (keepDelimiters && !m.captured(3).isEmpty()) res+=m.captured(3).trimmed();
if (++found==max) return res += value;
} }
return res; return res;
} }
@ -2609,12 +2614,12 @@ class Check: public Command {
std::shared_ptr<Check> cmd(new Check()); std::shared_ptr<Check> cmd(new Check());
cmd->_next = 0; cmd->_next = 0;
QString comp("[=!.^~<>]"); QString comp("[=!.^~<>]");
QStringList allargs = quotedStrings(args, comp, true); QStringList allargs = quotedStrings(args, comp, true, 1);
if (allargs.size()<2 || allargs[1].size()!=1 || if (allargs.size()<2 || allargs[1].size()!=1 ||
!QRegularExpression("^"+comp+"$").match(allargs[1]).hasMatch()) !QRegularExpression("^"+comp+"$").match(allargs[1]).hasMatch())
throw BadArgument(tag()+" needs a comparision, not: "+args); throw BadArgument(tag()+" needs a comparision, not: "+args, allargs);
if (allargs.size()>3) if (allargs.size()>3)
throw BadArgument(tag()+" has at most three arguments"); throw BadArgument(tag()+" has at most three arguments", allargs);
cmd->_value1 = allargs[0]; cmd->_value1 = allargs[0];
cmd->_cmp = allargs[1][0].toLatin1(); cmd->_cmp = allargs[1][0].toLatin1();
if (allargs.size()==3) { if (allargs.size()==3) {
@ -2623,7 +2628,7 @@ class Check: public Command {
if (in.size() && in.first().contains(QRegularExpression("^ "))) { if (in.size() && in.first().contains(QRegularExpression("^ "))) {
cmd->_next = script->parseLine(in, file, line+1, indent+1); cmd->_next = script->parseLine(in, file, line+1, indent+1);
cmd->_next->log(false); // suppress logging of subcommand cmd->_next->log(false); // suppress logging of subcommand
} else throw BadArgument(tag()+" needs a third argument or a following command"); } else throw BadArgument(tag()+" needs a third argument or a following command", allargs);
} }
return cmd; return cmd;
} }

@ -59,6 +59,9 @@ class UnknownCommand: public ParseError {
class BadArgument: public ParseError { class BadArgument: public ParseError {
public: public:
BadArgument(QString arg): ParseError("bad argument:"+p(arg)) {} BadArgument(QString arg): ParseError("bad argument:"+p(arg)) {}
BadArgument(QString arg, QStringList args):
ParseError("bad argument:"+p(arg)+p("→ arguments:"+pq(args))) {
}
}; };
class MissingArguments: public ParseError { class MissingArguments: public ParseError {

Loading…
Cancel
Save