diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 22:42:29 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 22:42:29 +0000 |
commit | ba1321d147d0a2a3e05fb573a4627ca1ba34b357 (patch) | |
tree | c009e15b7675fdde482ec99f5361c6e63bb6bbde /chrome | |
parent | 7f1a907d93ee0f7ac527424a70e245343ce0539a (diff) | |
download | chromium_src-ba1321d147d0a2a3e05fb573a4627ca1ba34b357.zip chromium_src-ba1321d147d0a2a3e05fb573a4627ca1ba34b357.tar.gz chromium_src-ba1321d147d0a2a3e05fb573a4627ca1ba34b357.tar.bz2 |
posix: URLFixerUpper would DCHECK on input "/".
Also, add some more tests to cover this case.
Review URL: http://codereview.chromium.org/87048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/net/url_fixer_upper.cc | 12 | ||||
-rw-r--r-- | chrome/browser/net/url_fixer_upper_unittest.cc | 11 |
2 files changed, 17 insertions, 6 deletions
diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index 9fb17c4..edccfa0 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -103,18 +103,20 @@ static bool ValidPathForFile(const FilePath::StringType& text, // file: URLs: these don't look like filenames), leaving fixed_up_url // unchanged. static string FixupPath(const string& text) { - DCHECK(text.length() >= 2); + DCHECK(!text.empty()); FilePath::StringType filename; #if defined(OS_WIN) FilePath input_path(UTF8ToWide(text)); -#elif defined(OS_POSIX) - FilePath input_path(text); -#endif PrepareStringForFileOps(input_path, &filename); - if (filename[1] == '|') + // Fixup Windows-style drive letters, where "C:" gets rewritten to "C|". + if (filename.length() > 1 && filename[1] == '|') filename[1] = ':'; +#elif defined(OS_POSIX) + FilePath input_path(text); + PrepareStringForFileOps(input_path, &filename); +#endif // Here, we know the input looks like a file. GURL file_url = net::FilePathToFileURL(FilePath(filename)); diff --git a/chrome/browser/net/url_fixer_upper_unittest.cc b/chrome/browser/net/url_fixer_upper_unittest.cc index ccc111e..f7b0592 100644 --- a/chrome/browser/net/url_fixer_upper_unittest.cc +++ b/chrome/browser/net/url_fixer_upper_unittest.cc @@ -294,12 +294,21 @@ TEST(URLFixerUpperTest, FixupFile) { // {"file://server/folder/file", "", "file://server/folder/file"}, // {"file:/\\/server\\folder/file", "", "file://server/folder/file"}, }; +#elif defined(OS_POSIX) + fixup_case file_cases[] = { + // File URLs go through GURL, which tries to escape intelligently. + {"/This%20is a non-existent file.txt", "", + "file:///This%2520is%20a%20non-existent%20file.txt"}, + // A plain "/" refers to the root. + {"/", "", + "file:///"}, + }; +#endif for (size_t i = 0; i < arraysize(file_cases); i++) { fixedup = URLFixerUpper::FixupURL(file_cases[i].input, file_cases[i].desired_tld); EXPECT_EQ(file_cases[i].output, fixedup); } -#endif EXPECT_TRUE(file_util::Delete(original, false)); } |