Commit b45fe1fa authored by mgiuca's avatar mgiuca Committed by Commit bot

shell_util: AddFileAssociations now correctly quotes "%1" arguments.

Instead of GetCommandLineString, uses
GetCommandLineStringWithPlaceholders, which is specially designed to
quote placeholder arguments like "%1". This is necessary when writing a
command line to the Windows registry, because otherwise Windows may put
a filename with a space in it, and recognise it as two separate
arguments.

BUG=130455

Review URL: https://codereview.chromium.org/669943003

Cr-Commit-Position: refs/heads/master@{#301114}
parent 96b7b47e
......@@ -2445,7 +2445,7 @@ bool ShellUtil::AddFileAssociations(
app_info.file_type_name = file_type_name;
app_info.file_type_icon_path = icon_path.value();
app_info.file_type_icon_index = 0;
app_info.command_line = command_line.GetCommandLineString();
app_info.command_line = command_line.GetCommandLineStringWithPlaceholders();
RegistryEntry::GetProgIdEntries(app_info, &entries);
// Associate each extension that the app can handle with the class. Set this
......
......@@ -825,7 +825,10 @@ class ShellUtilRegistryTest : public testing::Test {
static base::CommandLine OpenCommand() {
base::FilePath open_command_path(kTestOpenCommand);
return base::CommandLine(open_command_path);
base::CommandLine open_command(open_command_path);
// The "%1" should automatically be quoted.
open_command.AppendArg("%1");
return open_command;
}
static std::set<base::string16> FileExtensions() {
......@@ -868,7 +871,7 @@ TEST_F(ShellUtilRegistryTest, AddFileAssociations) {
L"Software\\Classes\\TestApp\\shell\\open\\command",
KEY_READ));
EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(L"", &value));
EXPECT_EQ(L"\"C:\\test.exe\"", value);
EXPECT_EQ(L"\"C:\\test.exe\" \"%1\"", value);
// .test1 should be default-associated with our test app.
ASSERT_EQ(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment