summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMatthew Woehlke <matthew.woehlke@kitware.com>2016-09-28 16:07:39 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-28 18:18:20 (GMT)
commit41291b20f3881cac781e5e628f8b892b29c7b39c (patch)
treee36f76ea8719cef0580d1cfdbae112e5e4d48b27 /Source
parent8f25f37676cb860348738eff4dfb1c3b8bae0b59 (diff)
downloadCMake-41291b20f3881cac781e5e628f8b892b29c7b39c.zip
CMake-41291b20f3881cac781e5e628f8b892b29c7b39c.tar.gz
CMake-41291b20f3881cac781e5e628f8b892b29c7b39c.tar.bz2
cmake_parse_arguments: Fix PARSE_ARGV multi-value argument handling
The `PARSE_ARGV` mode was recently added to help functions properly parse their arguments even when those arguments may be quoted and contain literal `;` in their values. Fix the implementation to encode `;`s in reported multi-value arguments and in `UNPARSED_ARGUMENTS` so that `;`s in the individual values are preserved in the lists. This allows clients to access all their argument values correctly.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmParseArgumentsCommand.cxx25
1 files changed, 23 insertions, 2 deletions
diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx
index e8de5b6..55d71ea 100644
--- a/Source/cmParseArgumentsCommand.cxx
+++ b/Source/cmParseArgumentsCommand.cxx
@@ -4,6 +4,19 @@
#include "cmAlgorithms.h"
+static std::string escape_arg(const std::string& arg)
+{
+ // replace ";" with "\;" so output argument lists will split correctly
+ std::string escapedArg;
+ for (size_t i = 0; i < arg.size(); ++i) {
+ if (arg[i] == ';') {
+ escapedArg += '\\';
+ }
+ escapedArg += arg[i];
+ }
+ return escapedArg;
+}
+
bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
@@ -165,10 +178,18 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
insideValues = NONE;
break;
case MULTI:
- multi[currentArgName].push_back(*argIter);
+ if (parseFromArgV) {
+ multi[currentArgName].push_back(escape_arg(*argIter));
+ } else {
+ multi[currentArgName].push_back(*argIter);
+ }
break;
default:
- unparsed.push_back(*argIter);
+ if (parseFromArgV) {
+ unparsed.push_back(escape_arg(*argIter));
+ } else {
+ unparsed.push_back(*argIter);
+ }
break;
}
}