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

Unified Diff: base/command_line.h

Issue 595803002: base::CommandLine: Added optional quoting of placeholder arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase off CL 602253006. 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
« no previous file with comments | « no previous file | base/command_line.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/command_line.h
diff --git a/base/command_line.h b/base/command_line.h
index 84bca28b93c0099e42fa677630ebc4c2ba325663..1829e63e1b5b8e5b87b04af6ecd67a6bd414bebc 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -98,12 +98,41 @@ class BASE_EXPORT CommandLine {
// Constructs and returns the represented command line string.
// CAUTION! This should be avoided on POSIX because quoting behavior is
// unclear.
- StringType GetCommandLineString() const;
+ StringType GetCommandLineString() const {
+ return GetCommandLineStringInternal(false);
+ }
+
+#if defined(OS_WIN)
+ // Constructs and returns the represented command line string. Assumes the
+ // command line contains placeholders (eg, %1) and quotes any program or
+ // argument with a '%' in it. This should be avoided unless the placeholder is
+ // required by an external interface (eg, the Windows registry), because it is
+ // not generally safe to replace it with an arbitrary string. If possible,
+ // placeholders should be replaced *before* converting the command line to a
+ // string.
+ StringType GetCommandLineStringWithPlaceholders() const {
+ return GetCommandLineStringInternal(true);
+ }
+#endif
// Constructs and returns the represented arguments string.
// CAUTION! This should be avoided on POSIX because quoting behavior is
// unclear.
- StringType GetArgumentsString() const;
+ StringType GetArgumentsString() const {
+ return GetArgumentsStringInternal(false);
+ }
+
+#if defined(OS_WIN)
+ // Constructs and returns the represented arguments string. Assumes the
+ // command line contains placeholders (eg, %1) and quotes any argument with a
+ // '%' in it. This should be avoided unless the placeholder is required by an
+ // external interface (eg, the Windows registry), because it is not generally
+ // safe to replace it with an arbitrary string. If possible, placeholders
+ // should be replaced *before* converting the arguments to a string.
+ StringType GetArgumentsStringWithPlaceholders() const {
+ return GetArgumentsStringInternal(true);
+ }
+#endif
// Returns the original command line string as a vector of strings.
const StringVector& argv() const { return argv_; }
@@ -174,6 +203,14 @@ class BASE_EXPORT CommandLine {
// CommandLine cl(*CommandLine::ForCurrentProcess());
// cl.AppendSwitch(...);
+ // Internal version of GetCommandLineString. If |quote_placeholders| is true,
+ // also quotes parts with '%' in them.
+ StringType GetCommandLineStringInternal(bool quote_placeholders) const;
+
+ // Internal version of GetArgumentsString. If |quote_placeholders| is true,
+ // also quotes parts with '%' in them.
+ StringType GetArgumentsStringInternal(bool quote_placeholders) const;
+
// The singleton CommandLine representing the current process's command line.
static CommandLine* current_process_commandline_;
« no previous file with comments | « no previous file | base/command_line.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698