base: CommandLine::RemoveSwitch should drop multiple same switches from argv
When there are multiple switches having the same key within the argv
array, CommandLine constructor only puts one of them within the
parsed-out switches map.
On the other hand, CommandLine::RemoveSwitch removes a switch from the
switches map. It should also drop all the switches having the same key
from the argv array.
BUG=957138
TEST=base_unittests --gtest_filter="CommandLineTest.*"
Change-Id: Ia4cf08bc497d4d53e0213879df71f85d945a4fec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724079
Auto-Submit: Andrei Polushin <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#682443}
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index d4194fc..28d1901 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -495,6 +495,28 @@
FILE_PATH_LITERAL("--switch1")));
}
+TEST(CommandLineTest, RemoveSwitchDropsMultipleSameSwitches) {
+ const std::string switch1 = "switch1";
+ const std::string value2 = "value2";
+
+ CommandLine cl(FilePath(FILE_PATH_LITERAL("Program")));
+
+ cl.AppendSwitch(switch1);
+ cl.AppendSwitchASCII(switch1, value2);
+
+ EXPECT_TRUE(cl.HasSwitch(switch1));
+ EXPECT_EQ(value2, cl.GetSwitchValueASCII(switch1));
+ EXPECT_THAT(cl.argv(),
+ testing::ElementsAre(FILE_PATH_LITERAL("Program"),
+ FILE_PATH_LITERAL("--switch1"),
+ FILE_PATH_LITERAL("--switch1=value2")));
+
+ cl.RemoveSwitch(switch1);
+
+ EXPECT_FALSE(cl.HasSwitch(switch1));
+ EXPECT_THAT(cl.argv(), testing::ElementsAre(FILE_PATH_LITERAL("Program")));
+}
+
TEST(CommandLineTest, AppendAndRemoveSwitchWithDefaultPrefix) {
CommandLine cl(FilePath(FILE_PATH_LITERAL("Program")));