Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2101)

Unified Diff: base/command_line.cc

Issue 2778173003: base: Support command line wrappers with quoted arguments (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/command_line_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | base/command_line_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698