From 39abe05d3ebc8e41704fca8af77ba0755dc40153 Mon Sep 17 00:00:00 2001 From: "ahendrickson@chromium.org" Date: Tue, 8 Feb 2011 22:50:30 +0000 Subject: Change backslashes in download file path to underscores. BUG=70702 TEST=Upload a file with apostrophes to mediafire.com, then download it. Review URL: http://codereview.chromium.org/6286125 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74193 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/net_util.cc | 9 ++++----- net/base/net_util_unittest.cc | 7 ++++++- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'net/base') diff --git a/net/base/net_util.cc b/net/base/net_util.cc index b4082ec..0528d50 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1398,11 +1398,10 @@ string16 GetSuggestedFilename(const GURL& url, referrer_charset); if (!filename.empty()) { - // Remove any path information the server may have sent, take the name - // only. - std::string::size_type slashpos = filename.find_last_of("/\\"); - if (slashpos != std::string::npos) - filename = filename.substr(slashpos + 1); + // Replace any path information the server may have sent, by changing + // path separators with underscores. + ReplaceSubstringsAfterOffset(&filename, 0, "/", "_"); + ReplaceSubstringsAfterOffset(&filename, 0, "\\", "_"); // Next, remove "." from the beginning and end of the file name to avoid // tricks with hidden files, "..", and "." diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index bf51f1c..ebb3574 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -1098,7 +1098,12 @@ TEST(NetUtilTest, GetSuggestedFilename) { "Content-disposition: attachment; filename=\"../test.html\"", "", L"", - L"test.html"}, + L"_test.html"}, + {"http://www.google.com/", + "Content-disposition: attachment; filename=\"..\\test.html\"", + "", + L"", + L"_test.html"}, {"http://www.google.com/", "Content-disposition: attachment; filename=\"..\"", "", -- cgit v1.1