From bedf4ca32a1103a128231b94c05ef1a475ff069f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 27 Nov 2019 16:48:04 +0100 Subject: [PATCH] fix check when the second argument contains operator-characters --- configure.ac | 2 +- src/commands.hxx | 21 +++++++++++++-------- src/exceptions.hxx | 3 +++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 69582b1..d9c2eee 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,7 @@ AM_INIT_AUTOMAKE([1.9 tar-pax]) AX_INIT_STANDARD_PROJECT # requirements, uncomment, what you need: -AX_USE_CXX +AX_USE_CXX_11 #AX_USE_LIBTOOL AX_USE_SCRIPTS AX_USE_DOXYGEN diff --git a/src/commands.hxx b/src/commands.hxx index cd4bd36..bcebba0 100644 --- a/src/commands.hxx +++ b/src/commands.hxx @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -210,24 +212,27 @@ class Command: public QObject { } QStringList quotedStrings(QString value, QString delimiter = " ", - bool keepDelimiters = false) const { + bool keepDelimiters = false, + unsigned int max = 0) const { QStringList res; QString quot("'\""); + unsigned int found(0); while (value=value.trimmed(), value.size()) { QRegularExpression re; int start(0); if (quot.contains(value[0])) { - re = QRegularExpression(value[0]+" *(("+delimiter+" *)|$)"); + re = QRegularExpression(value[0]+" *((("+delimiter+") *)|$)"); start = 1; } else { - re = QRegularExpression("( *"+delimiter+" *)|$"); + re = QRegularExpression(" *((("+delimiter+") *)|$)"); } int pos(value.indexOf(re, start)); if (pos cmd(new Check()); cmd->_next = 0; QString comp("[=!.^~<>]"); - QStringList allargs = quotedStrings(args, comp, true); + QStringList allargs = quotedStrings(args, comp, true, 1); if (allargs.size()<2 || allargs[1].size()!=1 || !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) - throw BadArgument(tag()+" has at most three arguments"); + throw BadArgument(tag()+" has at most three arguments", allargs); cmd->_value1 = allargs[0]; cmd->_cmp = allargs[1][0].toLatin1(); if (allargs.size()==3) { @@ -2623,7 +2628,7 @@ class Check: public Command { if (in.size() && in.first().contains(QRegularExpression("^ "))) { cmd->_next = script->parseLine(in, file, line+1, indent+1); 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; } diff --git a/src/exceptions.hxx b/src/exceptions.hxx index 9885d82..80295de 100644 --- a/src/exceptions.hxx +++ b/src/exceptions.hxx @@ -59,6 +59,9 @@ class UnknownCommand: public ParseError { class BadArgument: public ParseError { public: 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 {