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

Unified Diff: base/command_line.cc

Issue 595803002: base::CommandLine: Added optional quoting of placeholder arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert default behaviour; add optional argument to quote placeholder. Created 6 years, 3 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
Index: base/command_line.cc
diff --git a/base/command_line.cc b/base/command_line.cc
index ca4af9754cb07a22268992bee0a79f79ad313fc4..6694cd17da6b650637905413a06ae547667c15c4 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -105,10 +105,16 @@ std::string LowerASCIIOnWindows(const std::string& string) {
#if defined(OS_WIN)
// Quote a string as necessary for CommandLineToArgvW compatiblity *on Windows*.
-std::wstring QuoteForCommandLineToArgvW(const std::wstring& arg) {
+std::wstring QuoteForCommandLineToArgvW(const std::wstring& arg,
+ bool quote_placeholders) {
// We follow the quoting rules of CommandLineToArgvW.
// http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
- if (arg.find_first_of(L" \\\"") == std::wstring::npos) {
+ std::wstring quotable_chars(L" \\\"");
+ // We may also be required to quote '%', which is commonly used in a command
+ // line as a placeholder. (It may be substituted for a string with spaces.)
+ if (quote_placeholders)
+ quotable_chars.push_back(L'%');
+ if (arg.find_first_of(quotable_chars) == std::wstring::npos) {
// No quoting necessary.
return arg;
}
@@ -247,12 +253,13 @@ void CommandLine::InitFromArgv(const StringVector& argv) {
AppendSwitchesAndArguments(*this, argv);
}
-CommandLine::StringType CommandLine::GetCommandLineString() const {
+CommandLine::StringType CommandLine::GetCommandLineString(
+ bool quote_placeholders) const {
StringType string(argv_[0]);
#if defined(OS_WIN)
- string = QuoteForCommandLineToArgvW(string);
+ string = QuoteForCommandLineToArgvW(string, quote_placeholders);
#endif
- StringType params(GetArgumentsString());
+ StringType params(GetArgumentsString(quote_placeholders));
if (!params.empty()) {
string.append(StringType(FILE_PATH_LITERAL(" ")));
string.append(params);
@@ -260,7 +267,8 @@ CommandLine::StringType CommandLine::GetCommandLineString() const {
return string;
}
-CommandLine::StringType CommandLine::GetArgumentsString() const {
+CommandLine::StringType CommandLine::GetArgumentsString(
+ bool quote_placeholders) const {
StringType params;
// Append switches and arguments.
bool parse_switches = true;
@@ -275,14 +283,15 @@ CommandLine::StringType CommandLine::GetArgumentsString() const {
params.append(switch_string);
if (!switch_value.empty()) {
#if defined(OS_WIN)
- switch_value = QuoteForCommandLineToArgvW(switch_value);
+ switch_value =
+ QuoteForCommandLineToArgvW(switch_value, quote_placeholders);
#endif
params.append(kSwitchValueSeparator + switch_value);
}
}
else {
#if defined(OS_WIN)
- arg = QuoteForCommandLineToArgvW(arg);
+ arg = QuoteForCommandLineToArgvW(arg, quote_placeholders);
#endif
params.append(arg);
}
« base/command_line.h ('K') | « base/command_line.h ('k') | base/command_line_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698