Do not map URLs with empty paths
BUG=152448
TEST=ChromeContentBrowserClientBrowserTest.UberURLHandler_AboutPage
Review URL: https://chromiumcodereview.appspot.com/10989037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159322 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index b6314d8..8eae62dc 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -191,19 +191,23 @@
return ReplaceURLHostAndPath(url, uber_host, new_path);
}
-// If url->host() is "chrome", changes the url from "foo://chrome/bar/" to
-// "foo://bar/" and returns true. Otherwise returns false.
+// If url->host() is "chrome" and url->path() has characters other than the
+// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
+// returns true. Otherwise returns false.
bool RemoveUberHost(GURL* url) {
if (url->host() != chrome::kChromeUIUberHost)
return false;
+ if (url->path().empty() || url->path() == "/")
+ return false;
+
const std::string old_path = url->path();
const std::string::size_type separator = old_path.find('/', 1);
std::string new_host;
std::string new_path;
if (separator == std::string::npos) {
- new_host = old_path.empty() ? old_path : old_path.substr(1);
+ new_host = old_path.substr(1);
} else {
new_host = old_path.substr(1, separator - 1);
new_path = old_path.substr(separator);