Index: base/command_line.cc |
diff --git a/base/command_line.cc b/base/command_line.cc |
index 99ea2b000324b87ea4ab11bae1f7c5374586331c..e632d35b76fce4832927cdcad2d0da2de6cb3ba4 100644 |
--- a/base/command_line.cc |
+++ b/base/command_line.cc |
@@ -11,6 +11,7 @@ |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/strings/string_split.h" |
+#include "base/strings/string_tokenizer.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "build/build_config.h" |
@@ -411,14 +412,15 @@ void CommandLine::AppendArguments(const CommandLine& other, |
void CommandLine::PrependWrapper(const CommandLine::StringType& wrapper) { |
if (wrapper.empty()) |
return; |
- // The wrapper may have embedded arguments (like "gdb --args"). In this case, |
- // we don't pretend to do anything fancy, we just split on spaces. |
- StringVector wrapper_argv = SplitString( |
- wrapper, FilePath::StringType(1, ' '), base::TRIM_WHITESPACE, |
- base::SPLIT_WANT_ALL); |
- // Prepend the wrapper and update the switches/arguments |begin_args_|. |
- argv_.insert(argv_.begin(), wrapper_argv.begin(), wrapper_argv.end()); |
- begin_args_ += wrapper_argv.size(); |
+ // Split the wrapper command based on whitespace (with quoting). |
+ StringTokenizer tokenizer(wrapper, " "); |
gab
2017/03/28 17:03:59
This won't compile on Windows I think (CommandLine
Sami
2017/03/28 17:54:09
Ah, thanks for the tip! Done.
|
+ tokenizer.set_quote_chars("'\""); |
+ // Prepend the wrapper and update the switches/arguments |begin_args_| |
+ auto it = argv_.begin(); |
+ while (tokenizer.GetNext()) { |
+ it = argv_.emplace(it, tokenizer.token()) + 1; |
gab
2017/03/28 17:03:59
Pushing in front of vector repeatedly is inefficie
Sami
2017/03/28 17:54:09
Right you are -- done.
|
+ begin_args_++; |
gab
2017/03/28 17:04:00
Irrelevant after above comment but FWIW: prefer pr
Sami
2017/03/28 17:54:09
Acknowledged.
|
+ } |
} |
#if defined(OS_WIN) |