Commit 04ec8d77 authored by Nicolas Ouellet-Payeur's avatar Nicolas Ouellet-Payeur Committed by Commit Bot

[BrowserSwitcher] Unencode single-quotes in URL on Windows

IE doesn't seem to unencode single-quote characters (') in the query-string of a
URL. With this patch, Chrome unencodes single-quotes before sending it off to
IE.

Bug: 1030184
Change-Id: I0c5e21b5789dfe357272ea87ca33f3c486fec7ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2019762
Commit-Queue: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Auto-Submit: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734975}
parent f8eb126a
......@@ -78,6 +78,10 @@ void PercentEncodeCommas(std::wstring* url) {
}
}
void PercentUnencodeQuotes(std::wstring* url) {
base::ReplaceSubstringsAfterOffset(url, 0, L"%27", L"'");
}
std::wstring GetBrowserLocation(const wchar_t* regkey_name) {
DCHECK(regkey_name);
base::win::RegKey key;
......@@ -132,6 +136,9 @@ void AppendCommandLineArguments(base::CommandLine* cmd_line,
const std::vector<std::string>& raw_args,
const GURL& url) {
std::wstring url_spec = base::UTF8ToWide(url.spec());
// IE has some quirks with quote characters. Send them verbatim instead
// of percent-encoding them.
PercentUnencodeQuotes(&url_spec);
std::vector<std::wstring> command_line;
bool contains_url = false;
for (const auto& arg : raw_args) {
......@@ -212,6 +219,7 @@ bool AlternativeBrowserDriverImpl::TryLaunchWithDde(const GURL& url) {
// for the WWW_OpenURL verb and the url is trimmed on the first one.
// Spaces are already encoded by GURL.
std::wstring encoded_url(base::UTF8ToWide(url.spec()));
PercentUnencodeQuotes(&encoded_url);
PercentEncodeCommas(&encoded_url);
success =
......
......@@ -41,6 +41,11 @@ namespace {
const char kTestUrl[] = "http://example.com/foobar";
const char kTestUrlWithSpaces[] = "http://example.com/foobar baz";
#if defined(OS_WIN)
// Only referenced on Windows.
const char kTestUrlWithQuotes[] = "http://example.com/?q='world'";
#endif
// A URL that shouldn't trigger a switch.
const char kOtherUrl[] = "http://google.com/";
......@@ -106,9 +111,7 @@ base::CommandLine GenerateEchoCommandLine(const base::FilePath& output_file) {
#if defined(OS_WIN)
// cmd.exe /C echo ${url} > "output_file"
std::vector<std::wstring> args = {
L"cmd.exe",
base::UTF8ToUTF16(base::StringPrintf("/C echo ${url}> \"%s\"",
output_file.MaybeAsASCII().c_str())),
L"cmd.exe", L"/C", L"echo", L"${url}>", output_file.value().c_str(),
};
return base::CommandLine(std::move(args));
#else
......@@ -227,6 +230,48 @@ IN_PROC_BROWSER_TEST_F(BrowserSwitcherBrowserTest, DoesNotKeepSpaces) {
run_loop.Run();
}
#if defined(OS_WIN)
// IE has some quirks with quote characters. Make sure IE doesn't receive them
// percent-encoded.
IN_PROC_BROWSER_TEST_F(BrowserSwitcherBrowserTest, UnencodesSingleQUotes) {
base::FilePath temp_file =
GetTempDir().AppendASCII("UnencodesSingleQuotes.txt");
base::CommandLine cmd_line = GenerateEchoCommandLine(temp_file);
InitPolicies(provider(), cmd_line);
// We open a new tab, because closing the last tab in the browser
// causes the whole browser to close.
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(kTestUrlWithQuotes),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_NONE);
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(
[](base::FilePath path, base::OnceClosure quit) {
base::ScopedAllowBlockingForTesting allow_blocking;
base::File file(path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
ASSERT_TRUE(file.IsValid());
std::unique_ptr<char[]> buffer(new char[file.GetLength() + 1]);
buffer.get()[file.GetLength()] = '\0';
file.Read(0, buffer.get(), file.GetLength());
// Check that there's no space in the URL (i.e. replaced with %20).
EXPECT_EQ("http://example.com/?q='world'\r\n",
std::string(buffer.get()));
std::move(quit).Run();
},
std::move(temp_file), run_loop.QuitClosure()),
TestTimeouts::action_timeout());
run_loop.Run();
}
#endif
IN_PROC_BROWSER_TEST_F(BrowserSwitcherBrowserTest, DoesNotRunOnRandomUrls) {
base::FilePath temp_file =
GetTempDir().AppendASCII("DoesNotRunOnRandomUrls.txt");
......
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