Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/filename_util.h" | 5 #include "net/base/filename_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 GURL(test_case->url), test_case->content_disp_header, | 54 GURL(test_case->url), test_case->content_disp_header, |
| 55 test_case->referrer_charset, test_case->suggested_filename, | 55 test_case->referrer_charset, test_case->suggested_filename, |
| 56 test_case->mime_type, default_filename); | 56 test_case->mime_type, default_filename); |
| 57 EXPECT_EQ(test_case->expected_filename, FilePathAsWString(file_path)) | 57 EXPECT_EQ(test_case->expected_filename, FilePathAsWString(file_path)) |
| 58 << "test case at line number: " << test_case->lineno; | 58 << "test case at line number: " << test_case->lineno; |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 static const base::FilePath::CharType* kSafePortableBasenames[] = { | 63 static const base::FilePath::CharType* kSafePortableBasenames[] = { |
| 64 FILE_PATH_LITERAL("a"), | 64 FILE_PATH_LITERAL("a"), |
| 65 FILE_PATH_LITERAL("a.txt"), | 65 FILE_PATH_LITERAL("a.txt"), |
| 66 FILE_PATH_LITERAL("a b.txt"), | 66 FILE_PATH_LITERAL("a b.txt"), |
| 67 FILE_PATH_LITERAL("a-b.txt"), | 67 FILE_PATH_LITERAL("a-b.txt"), |
| 68 FILE_PATH_LITERAL("My Computer"), | 68 FILE_PATH_LITERAL("My Computer"), |
| 69 FILE_PATH_LITERAL(" Computer"), | 69 FILE_PATH_LITERAL(" Computer"), |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 static const base::FilePath::CharType* kUnsafePortableBasenames[] = { | 72 static const base::FilePath::CharType* kUnsafePortableBasenames[] = { |
| 73 FILE_PATH_LITERAL(""), | 73 FILE_PATH_LITERAL(""), |
| 74 FILE_PATH_LITERAL("."), | 74 FILE_PATH_LITERAL("."), |
| 75 FILE_PATH_LITERAL(".."), | 75 FILE_PATH_LITERAL(".."), |
| 76 FILE_PATH_LITERAL("..."), | 76 FILE_PATH_LITERAL("..."), |
| 77 FILE_PATH_LITERAL("con"), | 77 FILE_PATH_LITERAL("con"), |
| 78 FILE_PATH_LITERAL("con.zip"), | 78 FILE_PATH_LITERAL("con.zip"), |
| 79 FILE_PATH_LITERAL("NUL"), | 79 FILE_PATH_LITERAL("NUL"), |
| 80 FILE_PATH_LITERAL("NUL.zip"), | 80 FILE_PATH_LITERAL("NUL.zip"), |
| 81 FILE_PATH_LITERAL(".a"), | 81 FILE_PATH_LITERAL(".a"), |
| 82 FILE_PATH_LITERAL("a."), | 82 FILE_PATH_LITERAL("a."), |
| 83 FILE_PATH_LITERAL("a\"a"), | 83 FILE_PATH_LITERAL("a\"a"), |
| 84 FILE_PATH_LITERAL("a<a"), | 84 FILE_PATH_LITERAL("a<a"), |
| 85 FILE_PATH_LITERAL("a>a"), | 85 FILE_PATH_LITERAL("a>a"), |
| 86 FILE_PATH_LITERAL("a?a"), | 86 FILE_PATH_LITERAL("a?a"), |
| 87 FILE_PATH_LITERAL("a/"), | 87 FILE_PATH_LITERAL("a/"), |
| 88 FILE_PATH_LITERAL("a\\"), | 88 FILE_PATH_LITERAL("a\\"), |
| 89 FILE_PATH_LITERAL("a "), | 89 FILE_PATH_LITERAL("a "), |
| 90 FILE_PATH_LITERAL("a . ."), | 90 FILE_PATH_LITERAL("a . ."), |
| 91 FILE_PATH_LITERAL("My Computer.{a}"), | 91 FILE_PATH_LITERAL("My Computer.{a}"), |
| 92 FILE_PATH_LITERAL("My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), | 92 FILE_PATH_LITERAL("My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), |
| 93 #if !defined(OS_WIN) | 93 #if !defined(OS_WIN) |
| 94 FILE_PATH_LITERAL("a\\a"), | 94 FILE_PATH_LITERAL("a\\a"), |
| 95 #endif | 95 #endif |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 static const base::FilePath::CharType* kSafePortableRelativePaths[] = { | 98 static const base::FilePath::CharType* kSafePortableRelativePaths[] = { |
| 99 FILE_PATH_LITERAL("a/a"), | 99 FILE_PATH_LITERAL("a/a"), |
| 100 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 101 FILE_PATH_LITERAL("a\\a"), | 101 FILE_PATH_LITERAL("a\\a"), |
| 102 #endif | 102 #endif |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 TEST(FilenameUtilTest, IsSafePortablePathComponent) { | 105 TEST(FilenameUtilTest, IsSafePortablePathComponent) { |
| 106 for (size_t i = 0 ; i < arraysize(kSafePortableBasenames); ++i) { | 106 for (size_t i = 0; i < arraysize(kSafePortableBasenames); ++i) { |
| 107 EXPECT_TRUE(IsSafePortablePathComponent(base::FilePath( | 107 EXPECT_TRUE( |
| 108 kSafePortableBasenames[i]))) << kSafePortableBasenames[i]; | 108 IsSafePortablePathComponent(base::FilePath(kSafePortableBasenames[i]))) |
| 109 << kSafePortableBasenames[i]; | |
| 109 } | 110 } |
| 110 for (size_t i = 0 ; i < arraysize(kUnsafePortableBasenames); ++i) { | 111 for (size_t i = 0; i < arraysize(kUnsafePortableBasenames); ++i) { |
| 111 EXPECT_FALSE(IsSafePortablePathComponent(base::FilePath( | 112 EXPECT_FALSE(IsSafePortablePathComponent( |
| 112 kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; | 113 base::FilePath(kUnsafePortableBasenames[i]))) |
| 114 << kUnsafePortableBasenames[i]; | |
| 113 } | 115 } |
| 114 for (size_t i = 0 ; i < arraysize(kSafePortableRelativePaths); ++i) { | 116 for (size_t i = 0; i < arraysize(kSafePortableRelativePaths); ++i) { |
| 115 EXPECT_FALSE(IsSafePortablePathComponent(base::FilePath( | 117 EXPECT_FALSE(IsSafePortablePathComponent( |
| 116 kSafePortableRelativePaths[i]))) << kSafePortableRelativePaths[i]; | 118 base::FilePath(kSafePortableRelativePaths[i]))) |
| 119 << kSafePortableRelativePaths[i]; | |
| 117 } | 120 } |
| 118 } | 121 } |
| 119 | 122 |
| 120 TEST(FilenameUtilTest, IsSafePortableRelativePath) { | 123 TEST(FilenameUtilTest, IsSafePortableRelativePath) { |
| 121 base::FilePath safe_dirname(FILE_PATH_LITERAL("a")); | 124 base::FilePath safe_dirname(FILE_PATH_LITERAL("a")); |
| 122 for (size_t i = 0 ; i < arraysize(kSafePortableBasenames); ++i) { | 125 for (size_t i = 0; i < arraysize(kSafePortableBasenames); ++i) { |
| 123 EXPECT_TRUE(IsSafePortableRelativePath(base::FilePath( | 126 EXPECT_TRUE( |
| 124 kSafePortableBasenames[i]))) << kSafePortableBasenames[i]; | 127 IsSafePortableRelativePath(base::FilePath(kSafePortableBasenames[i]))) |
| 125 EXPECT_TRUE(IsSafePortableRelativePath(safe_dirname.Append(base::FilePath( | 128 << kSafePortableBasenames[i]; |
| 126 kSafePortableBasenames[i])))) << kSafePortableBasenames[i]; | 129 EXPECT_TRUE(IsSafePortableRelativePath( |
| 130 safe_dirname.Append(base::FilePath(kSafePortableBasenames[i])))) | |
| 131 << kSafePortableBasenames[i]; | |
| 127 } | 132 } |
| 128 for (size_t i = 0 ; i < arraysize(kSafePortableRelativePaths); ++i) { | 133 for (size_t i = 0; i < arraysize(kSafePortableRelativePaths); ++i) { |
| 129 EXPECT_TRUE(IsSafePortableRelativePath(base::FilePath( | 134 EXPECT_TRUE(IsSafePortableRelativePath( |
| 130 kSafePortableRelativePaths[i]))) << kSafePortableRelativePaths[i]; | 135 base::FilePath(kSafePortableRelativePaths[i]))) |
| 131 EXPECT_TRUE(IsSafePortableRelativePath(safe_dirname.Append(base::FilePath( | 136 << kSafePortableRelativePaths[i]; |
| 132 kSafePortableRelativePaths[i])))) << kSafePortableRelativePaths[i]; | 137 EXPECT_TRUE(IsSafePortableRelativePath( |
| 138 safe_dirname.Append(base::FilePath(kSafePortableRelativePaths[i])))) | |
| 139 << kSafePortableRelativePaths[i]; | |
| 133 } | 140 } |
| 134 for (size_t i = 0 ; i < arraysize(kUnsafePortableBasenames); ++i) { | 141 for (size_t i = 0; i < arraysize(kUnsafePortableBasenames); ++i) { |
| 135 EXPECT_FALSE(IsSafePortableRelativePath(base::FilePath( | 142 EXPECT_FALSE( |
| 136 kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; | 143 IsSafePortableRelativePath(base::FilePath(kUnsafePortableBasenames[i]))) |
| 144 << kUnsafePortableBasenames[i]; | |
| 137 if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { | 145 if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { |
| 138 EXPECT_FALSE(IsSafePortableRelativePath(safe_dirname.Append( | 146 EXPECT_FALSE(IsSafePortableRelativePath( |
| 139 base::FilePath(kUnsafePortableBasenames[i])))) | 147 safe_dirname.Append(base::FilePath(kUnsafePortableBasenames[i])))) |
| 140 << kUnsafePortableBasenames[i]; | 148 << kUnsafePortableBasenames[i]; |
| 141 } | 149 } |
| 142 } | 150 } |
| 143 } | 151 } |
| 144 | 152 |
| 145 TEST(FilenameUtilTest, FileURLConversion) { | 153 TEST(FilenameUtilTest, FileURLConversion) { |
| 146 // a list of test file names and the corresponding URLs | 154 // a list of test file names and the corresponding URLs |
| 147 const FileCase round_trip_cases[] = { | 155 const FileCase round_trip_cases[] = { |
| 148 #if defined(OS_WIN) | 156 #if defined(OS_WIN) |
| 149 {L"C:\\foo\\bar.txt", "file:///C:/foo/bar.txt"}, | 157 {L"C:\\foo\\bar.txt", "file:///C:/foo/bar.txt"}, |
| 150 {L"\\\\some computer\\foo\\bar.txt", | 158 {L"\\\\some computer\\foo\\bar.txt", |
| 151 "file://some%20computer/foo/bar.txt"}, // UNC | 159 "file://some%20computer/foo/bar.txt"}, // UNC |
| 152 {L"D:\\Name;with%some symbols*#", | 160 {L"D:\\Name;with%some symbols*#", |
| 153 "file:///D:/Name%3Bwith%25some%20symbols*%23"}, | 161 "file:///D:/Name%3Bwith%25some%20symbols*%23"}, |
| 154 // issue 14153: To be tested with the OS default codepage other than 1252. | 162 // issue 14153: To be tested with the OS default codepage other than 1252. |
| 155 {L"D:\\latin1\\caf\x00E9\x00DD.txt", | 163 {L"D:\\latin1\\caf\x00E9\x00DD.txt", |
| 156 "file:///D:/latin1/caf%C3%A9%C3%9D.txt"}, | 164 "file:///D:/latin1/caf%C3%A9%C3%9D.txt"}, |
| 157 {L"D:\\otherlatin\\caf\x0119.txt", | 165 {L"D:\\otherlatin\\caf\x0119.txt", "file:///D:/otherlatin/caf%C4%99.txt"}, |
| 158 "file:///D:/otherlatin/caf%C4%99.txt"}, | |
| 159 {L"D:\\greek\\\x03B1\x03B2\x03B3.txt", | 166 {L"D:\\greek\\\x03B1\x03B2\x03B3.txt", |
| 160 "file:///D:/greek/%CE%B1%CE%B2%CE%B3.txt"}, | 167 "file:///D:/greek/%CE%B1%CE%B2%CE%B3.txt"}, |
| 161 {L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", | 168 {L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", |
| 162 "file:///D:/Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91" | 169 "file:///D:/Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91" |
| 163 "%E9%A1%B5.doc"}, | 170 "%E9%A1%B5.doc"}, |
| 164 {L"D:\\plane1\\\xD835\xDC00\xD835\xDC01.txt", // Math alphabet "AB" | 171 {L"D:\\plane1\\\xD835\xDC00\xD835\xDC01.txt", // Math alphabet "AB" |
| 165 "file:///D:/plane1/%F0%9D%90%80%F0%9D%90%81.txt"}, | 172 "file:///D:/plane1/%F0%9D%90%80%F0%9D%90%81.txt"}, |
| 166 #elif defined(OS_POSIX) | 173 #elif defined(OS_POSIX) |
| 167 {L"/foo/bar.txt", "file:///foo/bar.txt"}, | 174 {L"/foo/bar.txt", "file:///foo/bar.txt"}, |
| 168 {L"/foo/BAR.txt", "file:///foo/BAR.txt"}, | 175 {L"/foo/BAR.txt", "file:///foo/BAR.txt"}, |
| 169 {L"/C:/foo/bar.txt", "file:///C:/foo/bar.txt"}, | 176 {L"/C:/foo/bar.txt", "file:///C:/foo/bar.txt"}, |
| 170 {L"/foo/bar?.txt", "file:///foo/bar%3F.txt"}, | 177 {L"/foo/bar?.txt", "file:///foo/bar%3F.txt"}, |
| 171 {L"/some computer/foo/bar.txt", "file:///some%20computer/foo/bar.txt"}, | 178 {L"/some computer/foo/bar.txt", "file:///some%20computer/foo/bar.txt"}, |
| 172 {L"/Name;with%some symbols*#", "file:///Name%3Bwith%25some%20symbols*%23"}, | 179 {L"/Name;with%some symbols*#", "file:///Name%3Bwith%25some%20symbols*%23"}, |
| 173 {L"/latin1/caf\x00E9\x00DD.txt", "file:///latin1/caf%C3%A9%C3%9D.txt"}, | 180 {L"/latin1/caf\x00E9\x00DD.txt", "file:///latin1/caf%C3%A9%C3%9D.txt"}, |
| 174 {L"/otherlatin/caf\x0119.txt", "file:///otherlatin/caf%C4%99.txt"}, | 181 {L"/otherlatin/caf\x0119.txt", "file:///otherlatin/caf%C4%99.txt"}, |
| 175 {L"/greek/\x03B1\x03B2\x03B3.txt", "file:///greek/%CE%B1%CE%B2%CE%B3.txt"}, | 182 {L"/greek/\x03B1\x03B2\x03B3.txt", "file:///greek/%CE%B1%CE%B2%CE%B3.txt"}, |
| 176 {L"/Chinese/\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", | 183 {L"/Chinese/\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc", |
| 177 "file:///Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD" | 184 "file:///Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD" |
| 178 "%91%E9%A1%B5.doc"}, | 185 "%91%E9%A1%B5.doc"}, |
| 179 {L"/plane1/\x1D400\x1D401.txt", // Math alphabet "AB" | 186 {L"/plane1/\x1D400\x1D401.txt", // Math alphabet "AB" |
| 180 "file:///plane1/%F0%9D%90%80%F0%9D%90%81.txt"}, | 187 "file:///plane1/%F0%9D%90%80%F0%9D%90%81.txt"}, |
| 181 #endif | 188 #endif |
| 182 }; | 189 }; |
| 183 | 190 |
| 184 // First, we'll test that we can round-trip all of the above cases of URLs | 191 // First, we'll test that we can round-trip all of the above cases of URLs |
| 185 base::FilePath output; | 192 base::FilePath output; |
| 186 for (size_t i = 0; i < arraysize(round_trip_cases); i++) { | 193 for (size_t i = 0; i < arraysize(round_trip_cases); i++) { |
| 187 // convert to the file URL | 194 // convert to the file URL |
| 188 GURL file_url(FilePathToFileURL( | 195 GURL file_url( |
| 189 WStringAsFilePath(round_trip_cases[i].file))); | 196 FilePathToFileURL(WStringAsFilePath(round_trip_cases[i].file))); |
| 190 EXPECT_EQ(round_trip_cases[i].url, file_url.spec()); | 197 EXPECT_EQ(round_trip_cases[i].url, file_url.spec()); |
| 191 | 198 |
| 192 // Back to the filename. | 199 // Back to the filename. |
| 193 EXPECT_TRUE(FileURLToFilePath(file_url, &output)); | 200 EXPECT_TRUE(FileURLToFilePath(file_url, &output)); |
| 194 EXPECT_EQ(round_trip_cases[i].file, FilePathAsWString(output)); | 201 EXPECT_EQ(round_trip_cases[i].file, FilePathAsWString(output)); |
| 195 } | 202 } |
| 196 | 203 |
| 197 // Test that various file: URLs get decoded into the correct file type | 204 // Test that various file: URLs get decoded into the correct file type |
| 198 FileCase url_cases[] = { | 205 FileCase url_cases[] = { |
| 199 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 212 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 219 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, |
| 213 {L"/foo/bar.txt", "file:foo/bar.txt"}, | 220 {L"/foo/bar.txt", "file:foo/bar.txt"}, |
| 214 {L"/bar.txt", "file://foo/bar.txt"}, | 221 {L"/bar.txt", "file://foo/bar.txt"}, |
| 215 {L"/foo/bar.txt", "file:///foo/bar.txt"}, | 222 {L"/foo/bar.txt", "file:///foo/bar.txt"}, |
| 216 {L"/foo/bar.txt", "file:////foo/bar.txt"}, | 223 {L"/foo/bar.txt", "file:////foo/bar.txt"}, |
| 217 {L"/foo/bar.txt", "file:////foo//bar.txt"}, | 224 {L"/foo/bar.txt", "file:////foo//bar.txt"}, |
| 218 {L"/foo/bar.txt", "file:////foo///bar.txt"}, | 225 {L"/foo/bar.txt", "file:////foo///bar.txt"}, |
| 219 {L"/foo/bar.txt", "file:////foo////bar.txt"}, | 226 {L"/foo/bar.txt", "file:////foo////bar.txt"}, |
| 220 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, | 227 {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"}, |
| 221 {L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"}, | 228 {L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"}, |
| 222 // We get these wrong because GURL turns back slashes into forward | 229 // We get these wrong because GURL turns back slashes into forward |
| 223 // slashes. | 230 // slashes. |
| 224 //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 231 //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, |
| 225 //{L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"}, | 232 //{L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"}, |
| 226 //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 233 //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, |
| 227 //{L"/foo%5Cbar.txt", "file:////foo\\bar.txt"}, | 234 //{L"/foo%5Cbar.txt", "file:////foo\\bar.txt"}, |
| 228 //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, | 235 //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"}, |
| 229 #endif | 236 #endif |
| 230 }; | 237 }; |
| 231 for (size_t i = 0; i < arraysize(url_cases); i++) { | 238 for (size_t i = 0; i < arraysize(url_cases); i++) { |
| 232 FileURLToFilePath(GURL(url_cases[i].url), &output); | 239 FileURLToFilePath(GURL(url_cases[i].url), &output); |
| 233 EXPECT_EQ(url_cases[i].file, FilePathAsWString(output)); | 240 EXPECT_EQ(url_cases[i].file, FilePathAsWString(output)); |
| 234 } | 241 } |
| 235 | 242 |
| 236 // Unfortunately, UTF8ToWide discards invalid UTF8 input. | 243 // Unfortunately, UTF8ToWide discards invalid UTF8 input. |
|
mmenke
2014/12/02 19:22:29
Hrm...wonder about the indentation of these commen
| |
| 237 #ifdef BUG_878908_IS_FIXED | 244 #ifdef BUG_878908_IS_FIXED |
| 238 // Test that no conversion happens if the UTF-8 input is invalid, and that | 245 // Test that no conversion happens if the UTF-8 input is invalid, and that |
| 239 // the input is preserved in UTF-8 | 246 // the input is preserved in UTF-8 |
| 240 const char invalid_utf8[] = "file:///d:/Blah/\xff.doc"; | 247 const char invalid_utf8[] = "file:///d:/Blah/\xff.doc"; |
| 241 const wchar_t invalid_wide[] = L"D:\\Blah\\\xff.doc"; | 248 const wchar_t invalid_wide[] = L"D:\\Blah\\\xff.doc"; |
| 242 EXPECT_TRUE(FileURLToFilePath( | 249 EXPECT_TRUE(FileURLToFilePath(GURL(std::string(invalid_utf8)), &output)); |
| 243 GURL(std::string(invalid_utf8)), &output)); | |
| 244 EXPECT_EQ(std::wstring(invalid_wide), output); | 250 EXPECT_EQ(std::wstring(invalid_wide), output); |
| 245 #endif | 251 #endif |
| 246 | 252 |
| 247 // Test that if a file URL is malformed, we get a failure | 253 // Test that if a file URL is malformed, we get a failure |
| 248 EXPECT_FALSE(FileURLToFilePath(GURL("filefoobar"), &output)); | 254 EXPECT_FALSE(FileURLToFilePath(GURL("filefoobar"), &output)); |
| 249 } | 255 } |
| 250 | 256 |
| 251 #if defined(OS_WIN) | 257 #if defined(OS_WIN) |
| 252 #define JPEG_EXT L".jpg" | 258 #define JPEG_EXT L".jpg" |
| 253 #define HTML_EXT L".htm" | 259 #define HTML_EXT L".htm" |
| 254 #elif defined(OS_MACOSX) | 260 #elif defined(OS_MACOSX) |
| 255 #define JPEG_EXT L".jpeg" | 261 #define JPEG_EXT L".jpeg" |
| 256 #define HTML_EXT L".html" | 262 #define HTML_EXT L".html" |
| 257 #else | 263 #else |
| 258 #define JPEG_EXT L".jpg" | 264 #define JPEG_EXT L".jpg" |
| 259 #define HTML_EXT L".html" | 265 #define HTML_EXT L".html" |
| 260 #endif | 266 #endif |
| 261 #define TXT_EXT L".txt" | 267 #define TXT_EXT L".txt" |
| 262 #define TAR_EXT L".tar" | 268 #define TAR_EXT L".tar" |
| 263 | 269 |
| 264 TEST(FilenameUtilTest, GenerateSafeFileName) { | 270 TEST(FilenameUtilTest, GenerateSafeFileName) { |
| 265 const struct { | 271 const struct { |
| 266 const char* mime_type; | 272 const char* mime_type; |
| 267 const base::FilePath::CharType* filename; | 273 const base::FilePath::CharType* filename; |
| 268 const base::FilePath::CharType* expected_filename; | 274 const base::FilePath::CharType* expected_filename; |
| 269 } safe_tests[] = { | 275 } safe_tests[] = { |
| 270 #if defined(OS_WIN) | 276 #if defined(OS_WIN) |
| 271 { | 277 {"text/html", |
| 272 "text/html", | 278 FILE_PATH_LITERAL("C:\\foo\\bar.htm"), |
| 273 FILE_PATH_LITERAL("C:\\foo\\bar.htm"), | 279 FILE_PATH_LITERAL("C:\\foo\\bar.htm")}, |
| 274 FILE_PATH_LITERAL("C:\\foo\\bar.htm") | 280 {"text/html", |
| 275 }, | 281 FILE_PATH_LITERAL("C:\\foo\\bar.html"), |
| 276 { | 282 FILE_PATH_LITERAL("C:\\foo\\bar.html")}, |
| 277 "text/html", | 283 {"text/html", |
| 278 FILE_PATH_LITERAL("C:\\foo\\bar.html"), | 284 FILE_PATH_LITERAL("C:\\foo\\bar"), |
| 279 FILE_PATH_LITERAL("C:\\foo\\bar.html") | 285 FILE_PATH_LITERAL("C:\\foo\\bar.htm")}, |
| 280 }, | 286 {"image/png", |
| 281 { | 287 FILE_PATH_LITERAL("C:\\bar.html"), |
| 282 "text/html", | 288 FILE_PATH_LITERAL("C:\\bar.html")}, |
| 283 FILE_PATH_LITERAL("C:\\foo\\bar"), | 289 {"image/png", |
| 284 FILE_PATH_LITERAL("C:\\foo\\bar.htm") | 290 FILE_PATH_LITERAL("C:\\bar"), |
| 285 }, | 291 FILE_PATH_LITERAL("C:\\bar.png")}, |
| 286 { | 292 {"text/html", |
| 287 "image/png", | 293 FILE_PATH_LITERAL("C:\\foo\\bar.exe"), |
| 288 FILE_PATH_LITERAL("C:\\bar.html"), | 294 FILE_PATH_LITERAL("C:\\foo\\bar.exe")}, |
| 289 FILE_PATH_LITERAL("C:\\bar.html") | 295 {"image/gif", |
| 290 }, | 296 FILE_PATH_LITERAL("C:\\foo\\bar.exe"), |
| 291 { | 297 FILE_PATH_LITERAL("C:\\foo\\bar.exe")}, |
| 292 "image/png", | 298 {"text/html", |
| 293 FILE_PATH_LITERAL("C:\\bar"), | 299 FILE_PATH_LITERAL("C:\\foo\\google.com"), |
| 294 FILE_PATH_LITERAL("C:\\bar.png") | 300 FILE_PATH_LITERAL("C:\\foo\\google.com")}, |
| 295 }, | 301 {"text/html", |
| 296 { | 302 FILE_PATH_LITERAL("C:\\foo\\con.htm"), |
| 297 "text/html", | 303 FILE_PATH_LITERAL("C:\\foo\\_con.htm")}, |
| 298 FILE_PATH_LITERAL("C:\\foo\\bar.exe"), | 304 {"text/html", |
| 299 FILE_PATH_LITERAL("C:\\foo\\bar.exe") | 305 FILE_PATH_LITERAL("C:\\foo\\con"), |
| 300 }, | 306 FILE_PATH_LITERAL("C:\\foo\\_con.htm")}, |
| 301 { | 307 {"text/html", |
| 302 "image/gif", | 308 FILE_PATH_LITERAL("C:\\foo\\harmless.{not-really-this-may-be-a-guid}"), |
| 303 FILE_PATH_LITERAL("C:\\foo\\bar.exe"), | 309 FILE_PATH_LITERAL("C:\\foo\\harmless.download")}, |
| 304 FILE_PATH_LITERAL("C:\\foo\\bar.exe") | 310 {"text/html", |
| 305 }, | 311 FILE_PATH_LITERAL("C:\\foo\\harmless.local"), |
| 306 { | 312 FILE_PATH_LITERAL("C:\\foo\\harmless.download")}, |
| 307 "text/html", | 313 {"text/html", |
| 308 FILE_PATH_LITERAL("C:\\foo\\google.com"), | 314 FILE_PATH_LITERAL("C:\\foo\\harmless.lnk"), |
| 309 FILE_PATH_LITERAL("C:\\foo\\google.com") | 315 FILE_PATH_LITERAL("C:\\foo\\harmless.download")}, |
| 310 }, | 316 {"text/html", |
| 311 { | 317 FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-"), |
| 312 "text/html", | 318 FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-")}, |
| 313 FILE_PATH_LITERAL("C:\\foo\\con.htm"), | |
| 314 FILE_PATH_LITERAL("C:\\foo\\_con.htm") | |
| 315 }, | |
| 316 { | |
| 317 "text/html", | |
| 318 FILE_PATH_LITERAL("C:\\foo\\con"), | |
| 319 FILE_PATH_LITERAL("C:\\foo\\_con.htm") | |
| 320 }, | |
| 321 { | |
| 322 "text/html", | |
| 323 FILE_PATH_LITERAL("C:\\foo\\harmless.{not-really-this-may-be-a-guid}"), | |
| 324 FILE_PATH_LITERAL("C:\\foo\\harmless.download") | |
| 325 }, | |
| 326 { | |
| 327 "text/html", | |
| 328 FILE_PATH_LITERAL("C:\\foo\\harmless.local"), | |
| 329 FILE_PATH_LITERAL("C:\\foo\\harmless.download") | |
| 330 }, | |
| 331 { | |
| 332 "text/html", | |
| 333 FILE_PATH_LITERAL("C:\\foo\\harmless.lnk"), | |
| 334 FILE_PATH_LITERAL("C:\\foo\\harmless.download") | |
| 335 }, | |
| 336 { | |
| 337 "text/html", | |
| 338 FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-"), | |
| 339 FILE_PATH_LITERAL("C:\\foo\\harmless.{mismatched-") | |
| 340 }, | |
| 341 // Allow extension synonyms. | 319 // Allow extension synonyms. |
| 342 { | 320 {"image/jpeg", |
| 343 "image/jpeg", | 321 FILE_PATH_LITERAL("C:\\foo\\bar.jpg"), |
| 344 FILE_PATH_LITERAL("C:\\foo\\bar.jpg"), | 322 FILE_PATH_LITERAL("C:\\foo\\bar.jpg")}, |
| 345 FILE_PATH_LITERAL("C:\\foo\\bar.jpg") | 323 {"image/jpeg", |
| 346 }, | 324 FILE_PATH_LITERAL("C:\\foo\\bar.jpeg"), |
| 347 { | 325 FILE_PATH_LITERAL("C:\\foo\\bar.jpeg")}, |
| 348 "image/jpeg", | 326 #else // !defined(OS_WIN) |
| 349 FILE_PATH_LITERAL("C:\\foo\\bar.jpeg"), | 327 {"text/html", |
| 350 FILE_PATH_LITERAL("C:\\foo\\bar.jpeg") | 328 FILE_PATH_LITERAL("/foo/bar.htm"), |
| 351 }, | 329 FILE_PATH_LITERAL("/foo/bar.htm")}, |
| 352 #else // !defined(OS_WIN) | 330 {"text/html", |
| 353 { | 331 FILE_PATH_LITERAL("/foo/bar.html"), |
| 354 "text/html", | 332 FILE_PATH_LITERAL("/foo/bar.html")}, |
| 355 FILE_PATH_LITERAL("/foo/bar.htm"), | 333 {"text/html", |
| 356 FILE_PATH_LITERAL("/foo/bar.htm") | 334 FILE_PATH_LITERAL("/foo/bar"), |
| 357 }, | 335 FILE_PATH_LITERAL("/foo/bar.html")}, |
| 358 { | 336 {"image/png", |
| 359 "text/html", | 337 FILE_PATH_LITERAL("/bar.html"), |
| 360 FILE_PATH_LITERAL("/foo/bar.html"), | 338 FILE_PATH_LITERAL("/bar.html")}, |
| 361 FILE_PATH_LITERAL("/foo/bar.html") | 339 {"image/png", FILE_PATH_LITERAL("/bar"), FILE_PATH_LITERAL("/bar.png")}, |
| 362 }, | 340 {"image/gif", |
| 363 { | 341 FILE_PATH_LITERAL("/foo/bar.exe"), |
| 364 "text/html", | 342 FILE_PATH_LITERAL("/foo/bar.exe")}, |
| 365 FILE_PATH_LITERAL("/foo/bar"), | 343 {"text/html", |
| 366 FILE_PATH_LITERAL("/foo/bar.html") | 344 FILE_PATH_LITERAL("/foo/google.com"), |
| 367 }, | 345 FILE_PATH_LITERAL("/foo/google.com")}, |
| 368 { | 346 {"text/html", |
| 369 "image/png", | 347 FILE_PATH_LITERAL("/foo/con.htm"), |
| 370 FILE_PATH_LITERAL("/bar.html"), | 348 FILE_PATH_LITERAL("/foo/con.htm")}, |
| 371 FILE_PATH_LITERAL("/bar.html") | 349 {"text/html", |
| 372 }, | 350 FILE_PATH_LITERAL("/foo/con"), |
| 373 { | 351 FILE_PATH_LITERAL("/foo/con.html")}, |
| 374 "image/png", | |
| 375 FILE_PATH_LITERAL("/bar"), | |
| 376 FILE_PATH_LITERAL("/bar.png") | |
| 377 }, | |
| 378 { | |
| 379 "image/gif", | |
| 380 FILE_PATH_LITERAL("/foo/bar.exe"), | |
| 381 FILE_PATH_LITERAL("/foo/bar.exe") | |
| 382 }, | |
| 383 { | |
| 384 "text/html", | |
| 385 FILE_PATH_LITERAL("/foo/google.com"), | |
| 386 FILE_PATH_LITERAL("/foo/google.com") | |
| 387 }, | |
| 388 { | |
| 389 "text/html", | |
| 390 FILE_PATH_LITERAL("/foo/con.htm"), | |
| 391 FILE_PATH_LITERAL("/foo/con.htm") | |
| 392 }, | |
| 393 { | |
| 394 "text/html", | |
| 395 FILE_PATH_LITERAL("/foo/con"), | |
| 396 FILE_PATH_LITERAL("/foo/con.html") | |
| 397 }, | |
| 398 // Allow extension synonyms. | 352 // Allow extension synonyms. |
| 399 { | 353 {"image/jpeg", |
| 400 "image/jpeg", | 354 FILE_PATH_LITERAL("/bar.jpg"), |
| 401 FILE_PATH_LITERAL("/bar.jpg"), | 355 FILE_PATH_LITERAL("/bar.jpg")}, |
| 402 FILE_PATH_LITERAL("/bar.jpg") | 356 {"image/jpeg", |
| 403 }, | 357 FILE_PATH_LITERAL("/bar.jpeg"), |
| 404 { | 358 FILE_PATH_LITERAL("/bar.jpeg")}, |
| 405 "image/jpeg", | |
| 406 FILE_PATH_LITERAL("/bar.jpeg"), | |
| 407 FILE_PATH_LITERAL("/bar.jpeg") | |
| 408 }, | |
| 409 #endif // !defined(OS_WIN) | 359 #endif // !defined(OS_WIN) |
| 410 }; | 360 }; |
| 411 | 361 |
| 412 for (size_t i = 0; i < arraysize(safe_tests); ++i) { | 362 for (size_t i = 0; i < arraysize(safe_tests); ++i) { |
| 413 base::FilePath file_path(safe_tests[i].filename); | 363 base::FilePath file_path(safe_tests[i].filename); |
| 414 GenerateSafeFileName(safe_tests[i].mime_type, false, &file_path); | 364 GenerateSafeFileName(safe_tests[i].mime_type, false, &file_path); |
| 415 EXPECT_EQ(safe_tests[i].expected_filename, file_path.value()) | 365 EXPECT_EQ(safe_tests[i].expected_filename, file_path.value()) |
| 416 << "Iteration " << i; | 366 << "Iteration " << i; |
| 417 } | 367 } |
| 418 } | 368 } |
| 419 | 369 |
| 420 TEST(FilenameUtilTest, GenerateFileName) { | 370 TEST(FilenameUtilTest, GenerateFileName) { |
| 421 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 371 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 422 // This test doesn't run when the locale is not UTF-8 because some of the | 372 // This test doesn't run when the locale is not UTF-8 because some of the |
| 423 // string conversions fail. This is OK (we have the default value) but they | 373 // string conversions fail. This is OK (we have the default value) but they |
| 424 // don't match our expectations. | 374 // don't match our expectations. |
| 425 std::string locale = setlocale(LC_CTYPE, NULL); | 375 std::string locale = setlocale(LC_CTYPE, NULL); |
| 426 base::StringToLowerASCII(&locale); | 376 base::StringToLowerASCII(&locale); |
| 427 EXPECT_TRUE(locale.find("utf-8") != std::string::npos || | 377 EXPECT_TRUE(locale.find("utf-8") != std::string::npos || |
| 428 locale.find("utf8") != std::string::npos) | 378 locale.find("utf8") != std::string::npos) |
| 429 << "Your locale (" << locale << ") must be set to UTF-8 " | 379 << "Your locale (" << locale << ") must be set to UTF-8 " |
| 430 << "for this test to pass!"; | 380 << "for this test to pass!"; |
| 431 #endif | 381 #endif |
| 432 | 382 |
| 433 // Tests whether the correct filename is selected from the the given | 383 // Tests whether the correct filename is selected from the the given |
| 434 // parameters and that Content-Disposition headers are properly | 384 // parameters and that Content-Disposition headers are properly |
| 435 // handled including failovers when the header is malformed. | 385 // handled including failovers when the header is malformed. |
| 436 const GenerateFilenameCase selection_tests[] = { | 386 const GenerateFilenameCase selection_tests[] = { |
| 437 { | 387 {__LINE__, |
| 438 __LINE__, | 388 "http://www.google.com/", |
| 439 "http://www.google.com/", | 389 "attachment; filename=test.html", |
| 440 "attachment; filename=test.html", | 390 "", |
| 441 "", | 391 "", |
| 442 "", | 392 "", |
| 443 "", | 393 L"", |
| 444 L"", | 394 L"test.html"}, |
| 445 L"test.html" | 395 {__LINE__, |
| 446 }, | 396 "http://www.google.com/", |
| 447 { | 397 "attachment; filename=\"test.html\"", |
| 448 __LINE__, | 398 "", |
| 449 "http://www.google.com/", | 399 "", |
| 450 "attachment; filename=\"test.html\"", | 400 "", |
| 451 "", | 401 L"", |
| 452 "", | 402 L"test.html"}, |
| 453 "", | 403 {__LINE__, |
| 454 L"", | 404 "http://www.google.com/", |
| 455 L"test.html" | 405 "attachment; filename= \"test.html\"", |
| 456 }, | 406 "", |
| 457 { | 407 "", |
| 458 __LINE__, | 408 "", |
| 459 "http://www.google.com/", | 409 L"", |
| 460 "attachment; filename= \"test.html\"", | 410 L"test.html"}, |
| 461 "", | 411 {__LINE__, |
| 462 "", | 412 "http://www.google.com/", |
| 463 "", | 413 "attachment; filename = \"test.html\"", |
| 464 L"", | 414 "", |
| 465 L"test.html" | 415 "", |
| 466 }, | 416 "", |
| 467 { | 417 L"", |
| 468 __LINE__, | 418 L"test.html"}, |
| 469 "http://www.google.com/", | 419 {// filename is whitespace. Should failover to URL host |
| 470 "attachment; filename = \"test.html\"", | 420 __LINE__, |
| 471 "", | 421 "http://www.google.com/", |
| 472 "", | 422 "attachment; filename= ", |
| 473 "", | 423 "", |
| 474 L"", | 424 "", |
| 475 L"test.html" | 425 "", |
| 476 }, | 426 L"", |
| 477 { // filename is whitespace. Should failover to URL host | 427 L"www.google.com"}, |
| 478 __LINE__, | 428 {// No filename. |
| 479 "http://www.google.com/", | 429 __LINE__, |
| 480 "attachment; filename= ", | 430 "http://www.google.com/path/test.html", |
| 481 "", | 431 "attachment", |
| 482 "", | 432 "", |
| 483 "", | 433 "", |
| 484 L"", | 434 "", |
| 485 L"www.google.com" | 435 L"", |
| 486 }, | 436 L"test.html"}, |
| 487 { // No filename. | 437 {// Ditto |
| 488 __LINE__, | 438 __LINE__, |
| 489 "http://www.google.com/path/test.html", | 439 "http://www.google.com/path/test.html", |
| 490 "attachment", | 440 "attachment;", |
| 491 "", | 441 "", |
| 492 "", | 442 "", |
| 493 "", | 443 "", |
| 494 L"", | 444 L"", |
| 495 L"test.html" | 445 L"test.html"}, |
| 496 }, | 446 {// No C-D |
| 497 { // Ditto | 447 __LINE__, |
| 498 __LINE__, | 448 "http://www.google.com/", |
| 499 "http://www.google.com/path/test.html", | 449 "", |
| 500 "attachment;", | 450 "", |
| 501 "", | 451 "", |
| 502 "", | 452 "", |
| 503 "", | 453 L"", |
| 504 L"", | 454 L"www.google.com"}, |
| 505 L"test.html" | 455 {__LINE__, |
| 506 }, | 456 "http://www.google.com/test.html", |
| 507 { // No C-D | 457 "", |
| 508 __LINE__, | 458 "", |
| 509 "http://www.google.com/", | 459 "", |
| 510 "", | 460 "", |
| 511 "", | 461 L"", |
| 512 "", | 462 L"test.html"}, |
| 513 "", | 463 {// Now that we use src/url's ExtractFileName, this case falls back to |
| 514 L"", | 464 // the hostname. If this behavior is not desirable, we'd better change |
| 515 L"www.google.com" | 465 // ExtractFileName (in url_parse.cc). |
| 516 }, | 466 __LINE__, |
| 517 { | 467 "http://www.google.com/path/", |
| 518 __LINE__, | 468 "", |
| 519 "http://www.google.com/test.html", | 469 "", |
| 520 "", | 470 "", |
| 521 "", | 471 "", |
| 522 "", | 472 L"", |
| 523 "", | 473 L"www.google.com"}, |
| 524 L"", | 474 {__LINE__, "http://www.google.com/path", "", "", "", "", L"", L"path"}, |
| 525 L"test.html" | 475 {__LINE__, "file:///", "", "", "", "", L"", L"download"}, |
| 526 }, | 476 {__LINE__, "file:///path/testfile", "", "", "", "", L"", L"testfile"}, |
| 527 { // Now that we use src/url's ExtractFileName, this case falls back to | 477 {__LINE__, "non-standard-scheme:", "", "", "", "", L"", L"download"}, |
| 528 // the hostname. If this behavior is not desirable, we'd better change | 478 {// C-D should override default |
| 529 // ExtractFileName (in url_parse.cc). | 479 __LINE__, |
| 530 __LINE__, | 480 "http://www.google.com/", |
| 531 "http://www.google.com/path/", | 481 "attachment; filename =\"test.html\"", |
| 532 "", | 482 "", |
| 533 "", | 483 "", |
| 534 "", | 484 "", |
| 535 "", | 485 L"download", |
| 536 L"", | 486 L"test.html"}, |
| 537 L"www.google.com" | 487 {// But the URL shouldn't |
| 538 }, | 488 __LINE__, |
| 539 { | 489 "http://www.google.com/", |
| 540 __LINE__, | 490 "", |
| 541 "http://www.google.com/path", | 491 "", |
| 542 "", | 492 "", |
| 543 "", | 493 "", |
| 544 "", | 494 L"download", |
| 545 "", | 495 L"download"}, |
| 546 L"", | 496 {__LINE__, |
| 547 L"path" | 497 "http://www.google.com/", |
| 548 }, | 498 "attachment; filename=\"../test.html\"", |
| 549 { | 499 "", |
| 550 __LINE__, | 500 "", |
| 551 "file:///", | 501 "", |
| 552 "", | 502 L"", |
| 553 "", | 503 L"-test.html"}, |
| 554 "", | 504 {__LINE__, |
| 555 "", | 505 "http://www.google.com/", |
| 556 L"", | 506 "attachment; filename=\"..\\test.html\"", |
| 557 L"download" | 507 "", |
| 558 }, | 508 "", |
| 559 { | 509 "", |
| 560 __LINE__, | 510 L"", |
| 561 "file:///path/testfile", | 511 L"test.html"}, |
| 562 "", | 512 {__LINE__, |
| 563 "", | 513 "http://www.google.com/", |
| 564 "", | 514 "attachment; filename=\"..\\\\test.html\"", |
| 565 "", | 515 "", |
| 566 L"", | 516 "", |
| 567 L"testfile" | 517 "", |
| 568 }, | 518 L"", |
| 569 { | 519 L"-test.html"}, |
| 570 __LINE__, | 520 {// Filename disappears after leading and trailing periods are removed. |
| 571 "non-standard-scheme:", | 521 __LINE__, |
| 572 "", | 522 "http://www.google.com/", |
| 573 "", | 523 "attachment; filename=\"..\"", |
| 574 "", | 524 "", |
| 575 "", | 525 "", |
| 576 L"", | 526 "", |
| 577 L"download" | 527 L"default", |
| 578 }, | 528 L"default"}, |
| 579 { // C-D should override default | 529 {// C-D specified filename disappears. Failover to final filename. |
| 580 __LINE__, | 530 __LINE__, |
| 581 "http://www.google.com/", | 531 "http://www.google.com/test.html", |
| 582 "attachment; filename =\"test.html\"", | 532 "attachment; filename=\"..\"", |
| 583 "", | 533 "", |
| 584 "", | 534 "", |
| 585 "", | 535 "", |
| 586 L"download", | 536 L"default", |
| 587 L"test.html" | 537 L"default"}, |
| 588 }, | |
| 589 { // But the URL shouldn't | |
| 590 __LINE__, | |
| 591 "http://www.google.com/", | |
| 592 "", | |
| 593 "", | |
| 594 "", | |
| 595 "", | |
| 596 L"download", | |
| 597 L"download" | |
| 598 }, | |
| 599 { | |
| 600 __LINE__, | |
| 601 "http://www.google.com/", | |
| 602 "attachment; filename=\"../test.html\"", | |
| 603 "", | |
| 604 "", | |
| 605 "", | |
| 606 L"", | |
| 607 L"-test.html" | |
| 608 }, | |
| 609 { | |
| 610 __LINE__, | |
| 611 "http://www.google.com/", | |
| 612 "attachment; filename=\"..\\test.html\"", | |
| 613 "", | |
| 614 "", | |
| 615 "", | |
| 616 L"", | |
| 617 L"test.html" | |
| 618 }, | |
| 619 { | |
| 620 __LINE__, | |
| 621 "http://www.google.com/", | |
| 622 "attachment; filename=\"..\\\\test.html\"", | |
| 623 "", | |
| 624 "", | |
| 625 "", | |
| 626 L"", | |
| 627 L"-test.html" | |
| 628 }, | |
| 629 { // Filename disappears after leading and trailing periods are removed. | |
| 630 __LINE__, | |
| 631 "http://www.google.com/", | |
| 632 "attachment; filename=\"..\"", | |
| 633 "", | |
| 634 "", | |
| 635 "", | |
| 636 L"default", | |
| 637 L"default" | |
| 638 }, | |
| 639 { // C-D specified filename disappears. Failover to final filename. | |
| 640 __LINE__, | |
| 641 "http://www.google.com/test.html", | |
| 642 "attachment; filename=\"..\"", | |
| 643 "", | |
| 644 "", | |
| 645 "", | |
| 646 L"default", | |
| 647 L"default" | |
| 648 }, | |
| 649 // Below is a small subset of cases taken from HttpContentDisposition tests. | 538 // Below is a small subset of cases taken from HttpContentDisposition tests. |
| 650 { | 539 {__LINE__, |
| 651 __LINE__, | 540 "http://www.google.com/", |
| 652 "http://www.google.com/", | 541 "attachment; filename=\"%EC%98%88%EC%88%A0%20" |
| 653 "attachment; filename=\"%EC%98%88%EC%88%A0%20" | 542 "%EC%98%88%EC%88%A0.jpg\"", |
| 654 "%EC%98%88%EC%88%A0.jpg\"", | 543 "", |
| 655 "", | 544 "", |
| 656 "", | 545 "", |
| 657 "", | 546 L"", |
| 658 L"", | 547 L"\uc608\uc220 \uc608\uc220.jpg"}, |
| 659 L"\uc608\uc220 \uc608\uc220.jpg" | 548 {__LINE__, |
| 660 }, | 549 "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", |
| 661 { | 550 "", |
| 662 __LINE__, | 551 "", |
| 663 "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", | 552 "", |
| 664 "", | 553 "", |
| 665 "", | 554 L"download", |
| 666 "", | 555 L"\uc608\uc220 \uc608\uc220.jpg"}, |
| 667 "", | 556 {__LINE__, |
| 668 L"download", | 557 "http://www.google.com/", |
| 669 L"\uc608\uc220 \uc608\uc220.jpg" | 558 "attachment;", |
| 670 }, | 559 "", |
| 671 { | 560 "", |
| 672 __LINE__, | 561 "", |
| 673 "http://www.google.com/", | 562 L"\uB2E4\uC6B4\uB85C\uB4DC", |
| 674 "attachment;", | 563 L"\uB2E4\uC6B4\uB85C\uB4DC"}, |
| 675 "", | 564 {__LINE__, |
| 676 "", | 565 "http://www.google.com/", |
| 677 "", | 566 "attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" |
| 678 L"\uB2E4\uC6B4\uB85C\uB4DC", | 567 "D13=2Epng?=\"", |
| 679 L"\uB2E4\uC6B4\uB85C\uB4DC" | 568 "", |
| 680 }, | 569 "", |
| 681 { | 570 "", |
| 682 __LINE__, | 571 L"download", |
| 683 "http://www.google.com/", | 572 L"\u82b8\u88533.png"}, |
| 684 "attachment; filename=\"=?EUC-JP?Q?=B7=DD=BD=" | 573 {__LINE__, |
| 685 "D13=2Epng?=\"", | 574 "http://www.example.com/images?id=3", |
| 686 "", | 575 "attachment; filename=caf\xc3\xa9.png", |
| 687 "", | 576 "iso-8859-1", |
| 688 "", | 577 "", |
| 689 L"download", | 578 "", |
| 690 L"\u82b8\u88533.png" | 579 L"", |
| 691 }, | 580 L"caf\u00e9.png"}, |
| 692 { | 581 {__LINE__, |
| 693 __LINE__, | 582 "http://www.example.com/images?id=3", |
| 694 "http://www.example.com/images?id=3", | 583 "attachment; filename=caf\xe5.png", |
| 695 "attachment; filename=caf\xc3\xa9.png", | 584 "windows-1253", |
| 696 "iso-8859-1", | 585 "", |
| 697 "", | 586 "", |
| 698 "", | 587 L"", |
| 699 L"", | 588 L"caf\u03b5.png"}, |
| 700 L"caf\u00e9.png" | 589 {__LINE__, |
| 701 }, | 590 "http://www.example.com/file?id=3", |
| 702 { | 591 "attachment; name=\xcf\xc2\xd4\xd8.zip", |
| 703 __LINE__, | 592 "GBK", |
| 704 "http://www.example.com/images?id=3", | 593 "", |
| 705 "attachment; filename=caf\xe5.png", | 594 "", |
| 706 "windows-1253", | 595 L"", |
| 707 "", | 596 L"\u4e0b\u8f7d.zip"}, |
| 708 "", | 597 {// Invalid C-D header. Extracts filename from url. |
| 709 L"", | 598 __LINE__, |
| 710 L"caf\u03b5.png" | 599 "http://www.google.com/test.html", |
| 711 }, | 600 "attachment; filename==?iiso88591?Q?caf=EG?=", |
| 712 { | 601 "", |
| 713 __LINE__, | 602 "", |
| 714 "http://www.example.com/file?id=3", | 603 "", |
| 715 "attachment; name=\xcf\xc2\xd4\xd8.zip", | 604 L"", |
| 716 "GBK", | 605 L"test.html"}, |
| 717 "", | |
| 718 "", | |
| 719 L"", | |
| 720 L"\u4e0b\u8f7d.zip" | |
| 721 }, | |
| 722 { // Invalid C-D header. Extracts filename from url. | |
| 723 __LINE__, | |
| 724 "http://www.google.com/test.html", | |
| 725 "attachment; filename==?iiso88591?Q?caf=EG?=", | |
| 726 "", | |
| 727 "", | |
| 728 "", | |
| 729 L"", | |
| 730 L"test.html" | |
| 731 }, | |
| 732 // about: and data: URLs | 606 // about: and data: URLs |
| 733 { | 607 {__LINE__, "about:chrome", "", "", "", "", L"", L"download"}, |
| 734 __LINE__, | 608 {__LINE__, "data:,looks/like/a.path", "", "", "", "", L"", L"download"}, |
| 735 "about:chrome", | 609 {__LINE__, |
| 736 "", | 610 "data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", |
| 737 "", | 611 "", |
| 738 "", | 612 "", |
| 739 "", | 613 "", |
| 740 L"", | 614 "", |
| 741 L"download" | 615 L"", |
| 742 }, | 616 L"download"}, |
| 743 { | 617 {__LINE__, |
| 744 __LINE__, | 618 "data:,looks/like/a.path", |
| 745 "data:,looks/like/a.path", | 619 "", |
| 746 "", | 620 "", |
| 747 "", | 621 "", |
| 748 "", | 622 "", |
| 749 "", | 623 L"default_filename_is_given", |
| 750 L"", | 624 L"default_filename_is_given"}, |
| 751 L"download" | 625 {__LINE__, |
| 752 }, | 626 "data:,looks/like/a.path", |
| 753 { | 627 "", |
| 754 __LINE__, | 628 "", |
| 755 "data:text/plain;base64,VG8gYmUgb3Igbm90IHRvIGJlLg=", | 629 "", |
| 756 "", | 630 "", |
| 757 "", | 631 L"\u65e5\u672c\u8a9e", // Japanese Kanji. |
| 758 "", | 632 L"\u65e5\u672c\u8a9e"}, |
| 759 "", | 633 {// The filename encoding is specified by the referrer charset. |
| 760 L"", | 634 __LINE__, |
| 761 L"download" | 635 "http://example.com/V%FDvojov%E1%20psychologie.doc", |
| 762 }, | 636 "", |
| 763 { | 637 "iso-8859-1", |
| 764 __LINE__, | 638 "", |
| 765 "data:,looks/like/a.path", | 639 "", |
| 766 "", | 640 L"", |
| 767 "", | 641 L"V\u00fdvojov\u00e1 psychologie.doc"}, |
| 768 "", | 642 {// Suggested filename takes precedence over URL |
| 769 "", | 643 __LINE__, |
| 770 L"default_filename_is_given", | 644 "http://www.google.com/test", |
| 771 L"default_filename_is_given" | 645 "", |
| 772 }, | 646 "", |
| 773 { | 647 "suggested", |
| 774 __LINE__, | 648 "", |
| 775 "data:,looks/like/a.path", | 649 L"", |
| 776 "", | 650 L"suggested"}, |
| 777 "", | 651 {// The content-disposition has higher precedence over the suggested name. |
| 778 "", | 652 __LINE__, |
| 779 "", | 653 "http://www.google.com/test", |
| 780 L"\u65e5\u672c\u8a9e", // Japanese Kanji. | 654 "attachment; filename=test.html", |
| 781 L"\u65e5\u672c\u8a9e" | 655 "", |
| 782 }, | 656 "suggested", |
| 783 { // The filename encoding is specified by the referrer charset. | 657 "", |
| 784 __LINE__, | 658 L"", |
| 785 "http://example.com/V%FDvojov%E1%20psychologie.doc", | 659 L"test.html"}, |
| 786 "", | 660 {__LINE__, |
| 787 "iso-8859-1", | 661 "http://www.google.com/test", |
| 788 "", | 662 "attachment; filename=test", |
| 789 "", | 663 "utf-8", |
| 790 L"", | 664 "", |
| 791 L"V\u00fdvojov\u00e1 psychologie.doc" | 665 "image/png", |
| 792 }, | 666 L"", |
| 793 { // Suggested filename takes precedence over URL | 667 L"test"}, |
| 794 __LINE__, | |
| 795 "http://www.google.com/test", | |
| 796 "", | |
| 797 "", | |
| 798 "suggested", | |
| 799 "", | |
| 800 L"", | |
| 801 L"suggested" | |
| 802 }, | |
| 803 { // The content-disposition has higher precedence over the suggested name. | |
| 804 __LINE__, | |
| 805 "http://www.google.com/test", | |
| 806 "attachment; filename=test.html", | |
| 807 "", | |
| 808 "suggested", | |
| 809 "", | |
| 810 L"", | |
| 811 L"test.html" | |
| 812 }, | |
| 813 { | |
| 814 __LINE__, | |
| 815 "http://www.google.com/test", | |
| 816 "attachment; filename=test", | |
| 817 "utf-8", | |
| 818 "", | |
| 819 "image/png", | |
| 820 L"", | |
| 821 L"test" | |
| 822 }, | |
| 823 #if 0 | 668 #if 0 |
| 824 { // The filename encoding doesn't match the referrer charset, the system | 669 { // The filename encoding doesn't match the referrer charset, the system |
| 825 // charset, or UTF-8. | 670 // charset, or UTF-8. |
| 826 // TODO(jshin): we need to handle this case. | 671 // TODO(jshin): we need to handle this case. |
| 827 __LINE__, | 672 __LINE__, |
| 828 "http://example.com/V%FDvojov%E1%20psychologie.doc", | 673 "http://example.com/V%FDvojov%E1%20psychologie.doc", |
| 829 "", | 674 "", |
| 830 "utf-8", | 675 "utf-8", |
| 831 "", | 676 "", |
| 832 "", | 677 "", |
| 833 L"", | 678 L"", |
| 834 L"V\u00fdvojov\u00e1 psychologie.doc", | 679 L"V\u00fdvojov\u00e1 psychologie.doc", |
| 835 }, | 680 }, |
| 836 #endif | 681 #endif |
| 837 // Raw 8bit characters in C-D | 682 // Raw 8bit characters in C-D |
| 838 { | 683 {__LINE__, |
| 839 __LINE__, | 684 "http://www.example.com/images?id=3", |
| 840 "http://www.example.com/images?id=3", | 685 "attachment; filename=caf\xc3\xa9.png", |
| 841 "attachment; filename=caf\xc3\xa9.png", | 686 "iso-8859-1", |
| 842 "iso-8859-1", | 687 "", |
| 843 "", | 688 "image/png", |
| 844 "image/png", | 689 L"", |
| 845 L"", | 690 L"caf\u00e9.png"}, |
| 846 L"caf\u00e9.png" | 691 {__LINE__, |
| 847 }, | 692 "http://www.example.com/images?id=3", |
| 848 { | 693 "attachment; filename=caf\xe5.png", |
| 849 __LINE__, | 694 "windows-1253", |
| 850 "http://www.example.com/images?id=3", | 695 "", |
| 851 "attachment; filename=caf\xe5.png", | 696 "image/png", |
| 852 "windows-1253", | 697 L"", |
| 853 "", | 698 L"caf\u03b5.png"}, |
| 854 "image/png", | 699 {// No 'filename' keyword in the disposition, use the URL |
| 855 L"", | 700 __LINE__, |
| 856 L"caf\u03b5.png" | 701 "http://www.evil.com/my_download.txt", |
| 857 }, | 702 "a_file_name.txt", |
| 858 { // No 'filename' keyword in the disposition, use the URL | 703 "", |
| 859 __LINE__, | 704 "", |
| 860 "http://www.evil.com/my_download.txt", | 705 "text/plain", |
| 861 "a_file_name.txt", | 706 L"download", |
| 862 "", | 707 L"my_download.txt"}, |
| 863 "", | 708 {// Spaces in the disposition file name |
| 864 "text/plain", | 709 __LINE__, |
| 865 L"download", | 710 "http://www.frontpagehacker.com/a_download.exe", |
| 866 L"my_download.txt" | 711 "filename=My Downloaded File.exe", |
| 867 }, | 712 "", |
| 868 { // Spaces in the disposition file name | 713 "", |
| 869 __LINE__, | 714 "application/octet-stream", |
| 870 "http://www.frontpagehacker.com/a_download.exe", | 715 L"download", |
| 871 "filename=My Downloaded File.exe", | 716 L"My Downloaded File.exe"}, |
| 872 "", | 717 {// % encoded |
| 873 "", | 718 __LINE__, |
| 874 "application/octet-stream", | 719 "http://www.examples.com/", |
| 875 L"download", | 720 "attachment; " |
| 876 L"My Downloaded File.exe" | 721 "filename=\"%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg\"", |
| 877 }, | 722 "", |
| 878 { // % encoded | 723 "", |
| 879 __LINE__, | 724 "image/jpeg", |
| 880 "http://www.examples.com/", | 725 L"download", |
| 881 "attachment; " | 726 L"\uc608\uc220 \uc608\uc220.jpg"}, |
| 882 "filename=\"%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg\"", | 727 {// name= parameter |
| 883 "", | 728 __LINE__, |
| 884 "", | 729 "http://www.examples.com/q.cgi?id=abc", |
| 885 "image/jpeg", | 730 "attachment; name=abc de.pdf", |
| 886 L"download", | 731 "", |
| 887 L"\uc608\uc220 \uc608\uc220.jpg" | 732 "", |
| 888 }, | 733 "application/octet-stream", |
| 889 { // name= parameter | 734 L"download", |
| 890 __LINE__, | 735 L"abc de.pdf"}, |
| 891 "http://www.examples.com/q.cgi?id=abc", | 736 {__LINE__, |
| 892 "attachment; name=abc de.pdf", | 737 "http://www.example.com/path", |
| 893 "", | 738 "filename=\"=?EUC-JP?Q?=B7=DD=BD=D13=2Epng?=\"", |
| 894 "", | 739 "", |
| 895 "application/octet-stream", | 740 "", |
| 896 L"download", | 741 "image/png", |
| 897 L"abc de.pdf" | 742 L"download", |
| 898 }, | 743 L"\x82b8\x8853" |
| 899 { | 744 L"3.png"}, |
| 900 __LINE__, | 745 {// The following two have invalid CD headers and filenames come from the |
| 901 "http://www.example.com/path", | 746 // URL. |
| 902 "filename=\"=?EUC-JP?Q?=B7=DD=BD=D13=2Epng?=\"", | 747 __LINE__, |
| 903 "", | 748 "http://www.example.com/test%20123", |
| 904 "", | 749 "attachment; filename==?iiso88591?Q?caf=EG?=", |
| 905 "image/png", | 750 "", |
| 906 L"download", | 751 "", |
| 907 L"\x82b8\x8853" L"3.png" | 752 "image/jpeg", |
| 908 }, | 753 L"download", |
| 909 { // The following two have invalid CD headers and filenames come from the | 754 L"test 123" JPEG_EXT}, |
| 910 // URL. | 755 {__LINE__, |
| 911 __LINE__, | 756 "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", |
| 912 "http://www.example.com/test%20123", | 757 "malformed_disposition", |
| 913 "attachment; filename==?iiso88591?Q?caf=EG?=", | 758 "", |
| 914 "", | 759 "", |
| 915 "", | 760 "image/jpeg", |
| 916 "image/jpeg", | 761 L"download", |
| 917 L"download", | 762 L"\uc608\uc220 \uc608\uc220.jpg"}, |
| 918 L"test 123" JPEG_EXT | 763 {// Invalid C-D. No filename from URL. Falls back to 'download'. |
| 919 }, | 764 __LINE__, |
| 920 { | 765 "http://www.google.com/path1/path2/", |
| 921 __LINE__, | 766 "attachment; filename==?iso88591?Q?caf=E3?", |
| 922 "http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg", | 767 "", |
| 923 "malformed_disposition", | 768 "", |
| 924 "", | 769 "image/jpeg", |
| 925 "", | 770 L"download", |
| 926 "image/jpeg", | 771 L"download" JPEG_EXT}, |
| 927 L"download", | |
| 928 L"\uc608\uc220 \uc608\uc220.jpg" | |
| 929 }, | |
| 930 { // Invalid C-D. No filename from URL. Falls back to 'download'. | |
| 931 __LINE__, | |
| 932 "http://www.google.com/path1/path2/", | |
| 933 "attachment; filename==?iso88591?Q?caf=E3?", | |
| 934 "", | |
| 935 "", | |
| 936 "image/jpeg", | |
| 937 L"download", | |
| 938 L"download" JPEG_EXT | |
| 939 }, | |
| 940 }; | 772 }; |
| 941 | 773 |
| 942 // Tests filename generation. Once the correct filename is | 774 // Tests filename generation. Once the correct filename is |
| 943 // selected, they should be passed through the validation steps and | 775 // selected, they should be passed through the validation steps and |
| 944 // a correct extension should be added if necessary. | 776 // a correct extension should be added if necessary. |
| 945 const GenerateFilenameCase generation_tests[] = { | 777 const GenerateFilenameCase generation_tests[] = { |
| 946 // Dotfiles. Ensures preceeding period(s) stripped. | 778 // Dotfiles. Ensures preceeding period(s) stripped. |
| 947 { | 779 {__LINE__, |
| 948 __LINE__, | 780 "http://www.google.com/.test.html", |
| 949 "http://www.google.com/.test.html", | 781 "", |
| 950 "", | 782 "", |
| 951 "", | 783 "", |
| 952 "", | 784 "", |
| 953 "", | 785 L"", |
| 954 L"", | 786 L"test.html"}, |
| 955 L"test.html" | 787 {__LINE__, "http://www.google.com/.test", "", "", "", "", L"", L"test"}, |
| 956 }, | 788 {__LINE__, "http://www.google.com/..test", "", "", "", "", L"", L"test"}, |
| 957 { | 789 {// Disposition has relative paths, remove directory separators |
| 958 __LINE__, | 790 __LINE__, |
| 959 "http://www.google.com/.test", | 791 "http://www.evil.com/my_download.txt", |
| 960 "", | 792 "filename=../../../../././../a_file_name.txt", |
| 961 "", | 793 "", |
| 962 "", | 794 "", |
| 963 "", | 795 "text/plain", |
| 964 L"", | 796 L"download", |
| 965 L"test" | 797 L"-..-..-..-.-.-..-a_file_name.txt"}, |
| 966 }, | 798 {// Disposition has parent directories, remove directory separators |
| 967 { | 799 __LINE__, |
| 968 __LINE__, | 800 "http://www.evil.com/my_download.txt", |
| 969 "http://www.google.com/..test", | 801 "filename=dir1/dir2/a_file_name.txt", |
| 970 "", | 802 "", |
| 971 "", | 803 "", |
| 972 "", | 804 "text/plain", |
| 973 "", | 805 L"download", |
| 974 L"", | 806 L"dir1-dir2-a_file_name.txt"}, |
| 975 L"test" | 807 {// Disposition has relative paths, remove directory separators |
| 976 }, | 808 __LINE__, |
| 977 { // Disposition has relative paths, remove directory separators | 809 "http://www.evil.com/my_download.txt", |
| 978 __LINE__, | 810 "filename=..\\..\\..\\..\\.\\.\\..\\a_file_name.txt", |
| 979 "http://www.evil.com/my_download.txt", | 811 "", |
| 980 "filename=../../../../././../a_file_name.txt", | 812 "", |
| 981 "", | 813 "text/plain", |
| 982 "", | 814 L"download", |
| 983 "text/plain", | 815 L"-..-..-..-.-.-..-a_file_name.txt"}, |
| 984 L"download", | 816 {// Disposition has parent directories, remove directory separators |
| 985 L"-..-..-..-.-.-..-a_file_name.txt" | 817 __LINE__, |
| 986 }, | 818 "http://www.evil.com/my_download.txt", |
| 987 { // Disposition has parent directories, remove directory separators | 819 "filename=dir1\\dir2\\a_file_name.txt", |
| 988 __LINE__, | 820 "", |
| 989 "http://www.evil.com/my_download.txt", | 821 "", |
| 990 "filename=dir1/dir2/a_file_name.txt", | 822 "text/plain", |
| 991 "", | 823 L"download", |
| 992 "", | 824 L"dir1-dir2-a_file_name.txt"}, |
| 993 "text/plain", | 825 {// No useful information in disposition or URL, use default |
| 994 L"download", | 826 __LINE__, |
| 995 L"dir1-dir2-a_file_name.txt" | 827 "http://www.truncated.com/path/", |
| 996 }, | 828 "", |
| 997 { // Disposition has relative paths, remove directory separators | 829 "", |
| 998 __LINE__, | 830 "", |
| 999 "http://www.evil.com/my_download.txt", | 831 "text/plain", |
| 1000 "filename=..\\..\\..\\..\\.\\.\\..\\a_file_name.txt", | 832 L"download", |
| 1001 "", | 833 L"download" TXT_EXT}, |
| 1002 "", | 834 {// Filename looks like HTML? |
| 1003 "text/plain", | 835 __LINE__, |
| 1004 L"download", | 836 "http://www.evil.com/get/malware/here", |
| 1005 L"-..-..-..-.-.-..-a_file_name.txt" | 837 "filename=\"<blink>Hello kitty</blink>\"", |
| 1006 }, | 838 "", |
| 1007 { // Disposition has parent directories, remove directory separators | 839 "", |
| 1008 __LINE__, | 840 "text/plain", |
| 1009 "http://www.evil.com/my_download.txt", | 841 L"default", |
| 1010 "filename=dir1\\dir2\\a_file_name.txt", | 842 L"-blink-Hello kitty--blink-"}, |
| 1011 "", | 843 {// A normal avi should get .avi and not .avi.avi |
| 1012 "", | 844 __LINE__, |
| 1013 "text/plain", | 845 "https://blah.google.com/misc/2.avi", |
| 1014 L"download", | 846 "", |
| 1015 L"dir1-dir2-a_file_name.txt" | 847 "", |
| 1016 }, | 848 "", |
| 1017 { // No useful information in disposition or URL, use default | 849 "video/x-msvideo", |
| 1018 __LINE__, | 850 L"download", |
| 1019 "http://www.truncated.com/path/", | 851 L"2.avi"}, |
| 1020 "", | 852 {// Extension generation |
| 1021 "", | 853 __LINE__, |
| 1022 "", | 854 "http://www.example.com/my-cat", |
| 1023 "text/plain", | 855 "filename=my-cat", |
| 1024 L"download", | 856 "", |
| 1025 L"download" TXT_EXT | 857 "", |
| 1026 }, | 858 "image/jpeg", |
| 1027 { // Filename looks like HTML? | 859 L"download", |
| 1028 __LINE__, | 860 L"my-cat"}, |
| 1029 "http://www.evil.com/get/malware/here", | 861 {__LINE__, |
| 1030 "filename=\"<blink>Hello kitty</blink>\"", | 862 "http://www.example.com/my-cat", |
| 1031 "", | 863 "filename=my-cat", |
| 1032 "", | 864 "", |
| 1033 "text/plain", | 865 "", |
| 1034 L"default", | 866 "text/plain", |
| 1035 L"-blink-Hello kitty--blink-" | 867 L"download", |
| 1036 }, | 868 L"my-cat"}, |
| 1037 { // A normal avi should get .avi and not .avi.avi | 869 {__LINE__, |
| 1038 __LINE__, | 870 "http://www.example.com/my-cat", |
| 1039 "https://blah.google.com/misc/2.avi", | 871 "filename=my-cat", |
| 1040 "", | 872 "", |
| 1041 "", | 873 "", |
| 1042 "", | 874 "text/html", |
| 1043 "video/x-msvideo", | 875 L"download", |
| 1044 L"download", | 876 L"my-cat"}, |
| 1045 L"2.avi" | 877 {// Unknown MIME type |
| 1046 }, | 878 __LINE__, |
| 1047 { // Extension generation | 879 "http://www.example.com/my-cat", |
| 1048 __LINE__, | 880 "filename=my-cat", |
| 1049 "http://www.example.com/my-cat", | 881 "", |
| 1050 "filename=my-cat", | 882 "", |
| 1051 "", | 883 "dance/party", |
| 1052 "", | 884 L"download", |
| 1053 "image/jpeg", | 885 L"my-cat"}, |
| 1054 L"download", | 886 {__LINE__, |
| 1055 L"my-cat" | 887 "http://www.example.com/my-cat.jpg", |
| 1056 }, | 888 "filename=my-cat.jpg", |
| 1057 { | 889 "", |
| 1058 __LINE__, | 890 "", |
| 1059 "http://www.example.com/my-cat", | 891 "text/plain", |
| 1060 "filename=my-cat", | 892 L"download", |
| 1061 "", | 893 L"my-cat.jpg"}, |
| 1062 "", | 894 // Windows specific tests |
| 1063 "text/plain", | 895 #if defined(OS_WIN) |
| 1064 L"download", | 896 {__LINE__, |
| 1065 L"my-cat" | 897 "http://www.goodguy.com/evil.exe", |
| 1066 }, | 898 "filename=evil.exe", |
| 1067 { | 899 "", |
| 1068 __LINE__, | 900 "", |
| 1069 "http://www.example.com/my-cat", | 901 "image/jpeg", |
| 1070 "filename=my-cat", | 902 L"download", |
| 1071 "", | 903 L"evil.exe"}, |
| 1072 "", | 904 {__LINE__, |
| 1073 "text/html", | 905 "http://www.goodguy.com/ok.exe", |
| 1074 L"download", | 906 "filename=ok.exe", |
| 1075 L"my-cat" | 907 "", |
| 1076 }, | 908 "", |
| 1077 { // Unknown MIME type | 909 "binary/octet-stream", |
| 1078 __LINE__, | 910 L"download", |
| 1079 "http://www.example.com/my-cat", | 911 L"ok.exe"}, |
| 1080 "filename=my-cat", | 912 {__LINE__, |
| 1081 "", | 913 "http://www.goodguy.com/evil.dll", |
| 1082 "", | 914 "filename=evil.dll", |
| 1083 "dance/party", | 915 "", |
| 1084 L"download", | 916 "", |
| 1085 L"my-cat" | 917 "dance/party", |
| 1086 }, | 918 L"download", |
| 1087 { | 919 L"evil.dll"}, |
| 1088 __LINE__, | 920 {__LINE__, |
| 1089 "http://www.example.com/my-cat.jpg", | 921 "http://www.goodguy.com/evil.exe", |
| 1090 "filename=my-cat.jpg", | 922 "filename=evil", |
| 1091 "", | 923 "", |
| 1092 "", | 924 "", |
| 1093 "text/plain", | 925 "application/rss+xml", |
| 1094 L"download", | 926 L"download", |
| 1095 L"my-cat.jpg" | 927 L"evil"}, |
| 1096 }, | |
| 1097 // Windows specific tests | |
| 1098 #if defined(OS_WIN) | |
| 1099 { | |
| 1100 __LINE__, | |
| 1101 "http://www.goodguy.com/evil.exe", | |
| 1102 "filename=evil.exe", | |
| 1103 "", | |
| 1104 "", | |
| 1105 "image/jpeg", | |
| 1106 L"download", | |
| 1107 L"evil.exe" | |
| 1108 }, | |
| 1109 { | |
| 1110 __LINE__, | |
| 1111 "http://www.goodguy.com/ok.exe", | |
| 1112 "filename=ok.exe", | |
| 1113 "", | |
| 1114 "", | |
| 1115 "binary/octet-stream", | |
| 1116 L"download", | |
| 1117 L"ok.exe" | |
| 1118 }, | |
| 1119 { | |
| 1120 __LINE__, | |
| 1121 "http://www.goodguy.com/evil.dll", | |
| 1122 "filename=evil.dll", | |
| 1123 "", | |
| 1124 "", | |
| 1125 "dance/party", | |
| 1126 L"download", | |
| 1127 L"evil.dll" | |
| 1128 }, | |
| 1129 { | |
| 1130 __LINE__, | |
| 1131 "http://www.goodguy.com/evil.exe", | |
| 1132 "filename=evil", | |
| 1133 "", | |
| 1134 "", | |
| 1135 "application/rss+xml", | |
| 1136 L"download", | |
| 1137 L"evil" | |
| 1138 }, | |
| 1139 // Test truncation of trailing dots and spaces | 928 // Test truncation of trailing dots and spaces |
| 1140 { | 929 {__LINE__, |
| 1141 __LINE__, | 930 "http://www.goodguy.com/evil.exe ", |
| 1142 "http://www.goodguy.com/evil.exe ", | 931 "filename=evil.exe ", |
| 1143 "filename=evil.exe ", | 932 "", |
| 1144 "", | 933 "", |
| 1145 "", | 934 "binary/octet-stream", |
| 1146 "binary/octet-stream", | 935 L"download", |
| 1147 L"download", | 936 L"evil.exe"}, |
| 1148 L"evil.exe" | 937 {__LINE__, |
| 1149 }, | 938 "http://www.goodguy.com/evil.exe.", |
| 1150 { | 939 "filename=evil.exe.", |
| 1151 __LINE__, | 940 "", |
| 1152 "http://www.goodguy.com/evil.exe.", | 941 "", |
| 1153 "filename=evil.exe.", | 942 "binary/octet-stream", |
| 1154 "", | 943 L"download", |
| 1155 "", | 944 L"evil.exe-"}, |
| 1156 "binary/octet-stream", | 945 {__LINE__, |
| 1157 L"download", | 946 "http://www.goodguy.com/evil.exe. . .", |
| 1158 L"evil.exe-" | 947 "filename=evil.exe. . .", |
| 1159 }, | 948 "", |
| 1160 { | 949 "", |
| 1161 __LINE__, | 950 "binary/octet-stream", |
| 1162 "http://www.goodguy.com/evil.exe. . .", | 951 L"download", |
| 1163 "filename=evil.exe. . .", | 952 L"evil.exe-------"}, |
| 1164 "", | 953 {__LINE__, |
| 1165 "", | 954 "http://www.goodguy.com/evil.", |
| 1166 "binary/octet-stream", | 955 "filename=evil.", |
| 1167 L"download", | 956 "", |
| 1168 L"evil.exe-------" | 957 "", |
| 1169 }, | 958 "binary/octet-stream", |
| 1170 { | 959 L"download", |
| 1171 __LINE__, | 960 L"evil-"}, |
| 1172 "http://www.goodguy.com/evil.", | 961 {__LINE__, |
| 1173 "filename=evil.", | 962 "http://www.goodguy.com/. . . . .", |
| 1174 "", | 963 "filename=. . . . .", |
| 1175 "", | 964 "", |
| 1176 "binary/octet-stream", | 965 "", |
| 1177 L"download", | 966 "binary/octet-stream", |
| 1178 L"evil-" | 967 L"download", |
| 1179 }, | 968 L"download"}, |
| 1180 { | 969 {__LINE__, |
| 1181 __LINE__, | 970 "http://www.badguy.com/attachment?name=meh.exe%C2%A0", |
| 1182 "http://www.goodguy.com/. . . . .", | 971 "attachment; filename=\"meh.exe\xC2\xA0\"", |
| 1183 "filename=. . . . .", | 972 "", |
| 1184 "", | 973 "", |
| 1185 "", | 974 "binary/octet-stream", |
| 1186 "binary/octet-stream", | 975 L"", |
| 1187 L"download", | 976 L"meh.exe-"}, |
| 1188 L"download" | |
| 1189 }, | |
| 1190 { | |
| 1191 __LINE__, | |
| 1192 "http://www.badguy.com/attachment?name=meh.exe%C2%A0", | |
| 1193 "attachment; filename=\"meh.exe\xC2\xA0\"", | |
| 1194 "", | |
| 1195 "", | |
| 1196 "binary/octet-stream", | |
| 1197 L"", | |
| 1198 L"meh.exe-" | |
| 1199 }, | |
| 1200 #endif // OS_WIN | 977 #endif // OS_WIN |
| 1201 { | 978 {__LINE__, |
| 1202 __LINE__, | 979 "http://www.goodguy.com/utils.js", |
| 1203 "http://www.goodguy.com/utils.js", | 980 "filename=utils.js", |
| 1204 "filename=utils.js", | 981 "", |
| 1205 "", | 982 "", |
| 1206 "", | 983 "application/x-javascript", |
| 1207 "application/x-javascript", | 984 L"download", |
| 1208 L"download", | 985 L"utils.js"}, |
| 1209 L"utils.js" | 986 {__LINE__, |
| 1210 }, | 987 "http://www.goodguy.com/contacts.js", |
| 1211 { | 988 "filename=contacts.js", |
| 1212 __LINE__, | 989 "", |
| 1213 "http://www.goodguy.com/contacts.js", | 990 "", |
| 1214 "filename=contacts.js", | 991 "application/json", |
| 1215 "", | 992 L"download", |
| 1216 "", | 993 L"contacts.js"}, |
| 1217 "application/json", | 994 {__LINE__, |
| 1218 L"download", | 995 "http://www.goodguy.com/utils.js", |
| 1219 L"contacts.js" | 996 "filename=utils.js", |
| 1220 }, | 997 "", |
| 1221 { | 998 "", |
| 1222 __LINE__, | 999 "text/javascript", |
| 1223 "http://www.goodguy.com/utils.js", | 1000 L"download", |
| 1224 "filename=utils.js", | 1001 L"utils.js"}, |
| 1225 "", | 1002 {__LINE__, |
| 1226 "", | 1003 "http://www.goodguy.com/utils.js", |
| 1227 "text/javascript", | 1004 "filename=utils.js", |
| 1228 L"download", | 1005 "", |
| 1229 L"utils.js" | 1006 "", |
| 1230 }, | 1007 "text/javascript;version=2", |
| 1231 { | 1008 L"download", |
| 1232 __LINE__, | 1009 L"utils.js"}, |
| 1233 "http://www.goodguy.com/utils.js", | 1010 {__LINE__, |
| 1234 "filename=utils.js", | 1011 "http://www.goodguy.com/utils.js", |
| 1235 "", | 1012 "filename=utils.js", |
| 1236 "", | 1013 "", |
| 1237 "text/javascript;version=2", | 1014 "", |
| 1238 L"download", | 1015 "application/ecmascript", |
| 1239 L"utils.js" | 1016 L"download", |
| 1240 }, | 1017 L"utils.js"}, |
| 1241 { | 1018 {__LINE__, |
| 1242 __LINE__, | 1019 "http://www.goodguy.com/utils.js", |
| 1243 "http://www.goodguy.com/utils.js", | 1020 "filename=utils.js", |
| 1244 "filename=utils.js", | 1021 "", |
| 1245 "", | 1022 "", |
| 1246 "", | 1023 "application/ecmascript;version=4", |
| 1247 "application/ecmascript", | 1024 L"download", |
| 1248 L"download", | 1025 L"utils.js"}, |
| 1249 L"utils.js" | 1026 {__LINE__, |
| 1250 }, | 1027 "http://www.goodguy.com/program.exe", |
| 1251 { | 1028 "filename=program.exe", |
| 1252 __LINE__, | 1029 "", |
| 1253 "http://www.goodguy.com/utils.js", | 1030 "", |
| 1254 "filename=utils.js", | 1031 "application/foo-bar", |
| 1255 "", | 1032 L"download", |
| 1256 "", | 1033 L"program.exe"}, |
| 1257 "application/ecmascript;version=4", | 1034 {__LINE__, |
| 1258 L"download", | 1035 "http://www.evil.com/../foo.txt", |
| 1259 L"utils.js" | 1036 "filename=../foo.txt", |
| 1260 }, | 1037 "", |
| 1261 { | 1038 "", |
| 1262 __LINE__, | 1039 "text/plain", |
| 1263 "http://www.goodguy.com/program.exe", | 1040 L"download", |
| 1264 "filename=program.exe", | 1041 L"-foo.txt"}, |
| 1265 "", | 1042 {__LINE__, |
| 1266 "", | 1043 "http://www.evil.com/..\\foo.txt", |
| 1267 "application/foo-bar", | 1044 "filename=..\\foo.txt", |
| 1268 L"download", | 1045 "", |
| 1269 L"program.exe" | 1046 "", |
| 1270 }, | 1047 "text/plain", |
| 1271 { | 1048 L"download", |
| 1272 __LINE__, | 1049 L"-foo.txt"}, |
| 1273 "http://www.evil.com/../foo.txt", | 1050 {__LINE__, |
| 1274 "filename=../foo.txt", | 1051 "http://www.evil.com/.hidden", |
| 1275 "", | 1052 "filename=.hidden", |
| 1276 "", | 1053 "", |
| 1277 "text/plain", | 1054 "", |
| 1278 L"download", | 1055 "text/plain", |
| 1279 L"-foo.txt" | 1056 L"download", |
| 1280 }, | 1057 L"hidden"}, |
| 1281 { | 1058 {__LINE__, |
| 1282 __LINE__, | 1059 "http://www.evil.com/trailing.", |
| 1283 "http://www.evil.com/..\\foo.txt", | 1060 "filename=trailing.", |
| 1284 "filename=..\\foo.txt", | 1061 "", |
| 1285 "", | 1062 "", |
| 1286 "", | 1063 "dance/party", |
| 1287 "text/plain", | 1064 L"download", |
| 1288 L"download", | 1065 #if defined(OS_WIN) |
| 1289 L"-foo.txt" | 1066 L"trailing-" |
| 1290 }, | 1067 #else |
| 1291 { | 1068 L"trailing" |
| 1292 __LINE__, | 1069 #endif |
| 1293 "http://www.evil.com/.hidden", | 1070 }, |
| 1294 "filename=.hidden", | 1071 {__LINE__, |
| 1295 "", | 1072 "http://www.evil.com/trailing.", |
| 1296 "", | 1073 "filename=trailing.", |
| 1297 "text/plain", | 1074 "", |
| 1298 L"download", | 1075 "", |
| 1299 L"hidden" | 1076 "text/plain", |
| 1300 }, | 1077 L"download", |
| 1301 { | 1078 #if defined(OS_WIN) |
| 1302 __LINE__, | 1079 L"trailing-" |
| 1303 "http://www.evil.com/trailing.", | 1080 #else |
| 1304 "filename=trailing.", | 1081 L"trailing" |
| 1305 "", | 1082 #endif |
| 1306 "", | 1083 }, |
| 1307 "dance/party", | 1084 {__LINE__, |
| 1308 L"download", | 1085 "http://www.evil.com/.", |
| 1309 #if defined(OS_WIN) | 1086 "filename=.", |
| 1310 L"trailing-" | 1087 "", |
| 1311 #else | 1088 "", |
| 1312 L"trailing" | 1089 "dance/party", |
| 1313 #endif | 1090 L"download", |
| 1314 }, | 1091 L"download"}, |
| 1315 { | 1092 {__LINE__, |
| 1316 __LINE__, | 1093 "http://www.evil.com/..", |
| 1317 "http://www.evil.com/trailing.", | 1094 "filename=..", |
| 1318 "filename=trailing.", | 1095 "", |
| 1319 "", | 1096 "", |
| 1320 "", | 1097 "dance/party", |
| 1321 "text/plain", | 1098 L"download", |
| 1322 L"download", | 1099 L"download"}, |
| 1323 #if defined(OS_WIN) | 1100 {__LINE__, |
| 1324 L"trailing-" | 1101 "http://www.evil.com/...", |
| 1325 #else | 1102 "filename=...", |
| 1326 L"trailing" | 1103 "", |
| 1327 #endif | 1104 "", |
| 1328 }, | 1105 "dance/party", |
| 1329 { | 1106 L"download", |
| 1330 __LINE__, | 1107 L"download"}, |
| 1331 "http://www.evil.com/.", | 1108 {// Note that this one doesn't have "filename=" on it. |
| 1332 "filename=.", | 1109 __LINE__, |
| 1333 "", | 1110 "http://www.evil.com/", |
| 1334 "", | 1111 "a_file_name.txt", |
| 1335 "dance/party", | 1112 "", |
| 1336 L"download", | 1113 "", |
| 1337 L"download" | 1114 "image/jpeg", |
| 1338 }, | 1115 L"download", |
| 1339 { | 1116 L"download" JPEG_EXT}, |
| 1340 __LINE__, | 1117 {__LINE__, |
| 1341 "http://www.evil.com/..", | 1118 "http://www.evil.com/", |
| 1342 "filename=..", | 1119 "filename=", |
| 1343 "", | 1120 "", |
| 1344 "", | 1121 "", |
| 1345 "dance/party", | 1122 "image/jpeg", |
| 1346 L"download", | 1123 L"download", |
| 1347 L"download" | 1124 L"download" JPEG_EXT}, |
| 1348 }, | 1125 {__LINE__, |
| 1349 { | 1126 "http://www.example.com/simple", |
| 1350 __LINE__, | 1127 "filename=simple", |
| 1351 "http://www.evil.com/...", | 1128 "", |
| 1352 "filename=...", | 1129 "", |
| 1353 "", | 1130 "application/octet-stream", |
| 1354 "", | 1131 L"download", |
| 1355 "dance/party", | 1132 L"simple"}, |
| 1356 L"download", | |
| 1357 L"download" | |
| 1358 }, | |
| 1359 { // Note that this one doesn't have "filename=" on it. | |
| 1360 __LINE__, | |
| 1361 "http://www.evil.com/", | |
| 1362 "a_file_name.txt", | |
| 1363 "", | |
| 1364 "", | |
| 1365 "image/jpeg", | |
| 1366 L"download", | |
| 1367 L"download" JPEG_EXT | |
| 1368 }, | |
| 1369 { | |
| 1370 __LINE__, | |
| 1371 "http://www.evil.com/", | |
| 1372 "filename=", | |
| 1373 "", | |
| 1374 "", | |
| 1375 "image/jpeg", | |
| 1376 L"download", | |
| 1377 L"download" JPEG_EXT | |
| 1378 }, | |
| 1379 { | |
| 1380 __LINE__, | |
| 1381 "http://www.example.com/simple", | |
| 1382 "filename=simple", | |
| 1383 "", | |
| 1384 "", | |
| 1385 "application/octet-stream", | |
| 1386 L"download", | |
| 1387 L"simple" | |
| 1388 }, | |
| 1389 // Reserved words on Windows | 1133 // Reserved words on Windows |
| 1390 { | 1134 {__LINE__, |
| 1391 __LINE__, | 1135 "http://www.goodguy.com/COM1", |
| 1392 "http://www.goodguy.com/COM1", | 1136 "filename=COM1", |
| 1393 "filename=COM1", | 1137 "", |
| 1394 "", | 1138 "", |
| 1395 "", | 1139 "application/foo-bar", |
| 1396 "application/foo-bar", | 1140 L"download", |
| 1397 L"download", | 1141 #if defined(OS_WIN) |
| 1398 #if defined(OS_WIN) | 1142 L"_COM1" |
| 1399 L"_COM1" | 1143 #else |
| 1400 #else | 1144 L"COM1" |
| 1401 L"COM1" | 1145 #endif |
| 1402 #endif | 1146 }, |
| 1403 }, | 1147 {__LINE__, |
| 1404 { | 1148 "http://www.goodguy.com/COM4.txt", |
| 1405 __LINE__, | 1149 "filename=COM4.txt", |
| 1406 "http://www.goodguy.com/COM4.txt", | 1150 "", |
| 1407 "filename=COM4.txt", | 1151 "", |
| 1408 "", | 1152 "text/plain", |
| 1409 "", | 1153 L"download", |
| 1410 "text/plain", | 1154 #if defined(OS_WIN) |
| 1411 L"download", | 1155 L"_COM4.txt" |
| 1412 #if defined(OS_WIN) | 1156 #else |
| 1413 L"_COM4.txt" | 1157 L"COM4.txt" |
| 1414 #else | 1158 #endif |
| 1415 L"COM4.txt" | 1159 }, |
| 1416 #endif | 1160 {__LINE__, |
| 1417 }, | 1161 "http://www.goodguy.com/lpt1.TXT", |
| 1418 { | 1162 "filename=lpt1.TXT", |
| 1419 __LINE__, | 1163 "", |
| 1420 "http://www.goodguy.com/lpt1.TXT", | 1164 "", |
| 1421 "filename=lpt1.TXT", | 1165 "text/plain", |
| 1422 "", | 1166 L"download", |
| 1423 "", | 1167 #if defined(OS_WIN) |
| 1424 "text/plain", | 1168 L"_lpt1.TXT" |
| 1425 L"download", | 1169 #else |
| 1426 #if defined(OS_WIN) | 1170 L"lpt1.TXT" |
| 1427 L"_lpt1.TXT" | 1171 #endif |
| 1428 #else | 1172 }, |
| 1429 L"lpt1.TXT" | 1173 {__LINE__, |
| 1430 #endif | 1174 "http://www.goodguy.com/clock$.txt", |
| 1431 }, | 1175 "filename=clock$.txt", |
| 1432 { | 1176 "", |
| 1433 __LINE__, | 1177 "", |
| 1434 "http://www.goodguy.com/clock$.txt", | 1178 "text/plain", |
| 1435 "filename=clock$.txt", | 1179 L"download", |
| 1436 "", | 1180 #if defined(OS_WIN) |
| 1437 "", | 1181 L"_clock$.txt" |
| 1438 "text/plain", | 1182 #else |
| 1439 L"download", | 1183 L"clock$.txt" |
| 1440 #if defined(OS_WIN) | 1184 #endif |
| 1441 L"_clock$.txt" | 1185 }, |
| 1442 #else | 1186 {// Validation should also apply to sugested name |
| 1443 L"clock$.txt" | 1187 __LINE__, |
| 1444 #endif | 1188 "http://www.goodguy.com/blah$.txt", |
| 1445 }, | 1189 "filename=clock$.txt", |
| 1446 { // Validation should also apply to sugested name | 1190 "", |
| 1447 __LINE__, | 1191 "clock$.txt", |
| 1448 "http://www.goodguy.com/blah$.txt", | 1192 "text/plain", |
| 1449 "filename=clock$.txt", | 1193 L"download", |
| 1450 "", | 1194 #if defined(OS_WIN) |
| 1451 "clock$.txt", | 1195 L"_clock$.txt" |
| 1452 "text/plain", | 1196 #else |
| 1453 L"download", | 1197 L"clock$.txt" |
| 1454 #if defined(OS_WIN) | 1198 #endif |
| 1455 L"_clock$.txt" | 1199 }, |
| 1456 #else | 1200 {__LINE__, |
| 1457 L"clock$.txt" | 1201 "http://www.goodguy.com/mycom1.foo", |
| 1458 #endif | 1202 "filename=mycom1.foo", |
| 1459 }, | 1203 "", |
| 1460 { | 1204 "", |
| 1461 __LINE__, | 1205 "text/plain", |
| 1462 "http://www.goodguy.com/mycom1.foo", | 1206 L"download", |
| 1463 "filename=mycom1.foo", | 1207 L"mycom1.foo"}, |
| 1464 "", | 1208 {__LINE__, |
| 1465 "", | 1209 "http://www.badguy.com/Setup.exe.local", |
| 1466 "text/plain", | 1210 "filename=Setup.exe.local", |
| 1467 L"download", | 1211 "", |
| 1468 L"mycom1.foo" | 1212 "", |
| 1469 }, | 1213 "application/foo-bar", |
| 1470 { | 1214 L"download", |
| 1471 __LINE__, | 1215 #if defined(OS_WIN) |
| 1472 "http://www.badguy.com/Setup.exe.local", | 1216 L"Setup.exe.download" |
| 1473 "filename=Setup.exe.local", | 1217 #else |
| 1474 "", | 1218 L"Setup.exe.local" |
| 1475 "", | 1219 #endif |
| 1476 "application/foo-bar", | 1220 }, |
| 1477 L"download", | 1221 {__LINE__, |
| 1478 #if defined(OS_WIN) | 1222 "http://www.badguy.com/Setup.exe.local", |
| 1479 L"Setup.exe.download" | 1223 "filename=Setup.exe.local.local", |
| 1480 #else | 1224 "", |
| 1481 L"Setup.exe.local" | 1225 "", |
| 1482 #endif | 1226 "application/foo-bar", |
| 1483 }, | 1227 L"download", |
| 1484 { | 1228 #if defined(OS_WIN) |
| 1485 __LINE__, | 1229 L"Setup.exe.local.download" |
| 1486 "http://www.badguy.com/Setup.exe.local", | 1230 #else |
| 1487 "filename=Setup.exe.local.local", | 1231 L"Setup.exe.local.local" |
| 1488 "", | 1232 #endif |
| 1489 "", | 1233 }, |
| 1490 "application/foo-bar", | 1234 {__LINE__, |
| 1491 L"download", | 1235 "http://www.badguy.com/Setup.exe.lnk", |
| 1492 #if defined(OS_WIN) | 1236 "filename=Setup.exe.lnk", |
| 1493 L"Setup.exe.local.download" | 1237 "", |
| 1494 #else | 1238 "", |
| 1495 L"Setup.exe.local.local" | 1239 "application/foo-bar", |
| 1496 #endif | 1240 L"download", |
| 1497 }, | 1241 #if defined(OS_WIN) |
| 1498 { | 1242 L"Setup.exe.download" |
| 1499 __LINE__, | 1243 #else |
| 1500 "http://www.badguy.com/Setup.exe.lnk", | 1244 L"Setup.exe.lnk" |
| 1501 "filename=Setup.exe.lnk", | 1245 #endif |
| 1502 "", | 1246 }, |
| 1503 "", | 1247 {__LINE__, |
| 1504 "application/foo-bar", | 1248 "http://www.badguy.com/Desktop.ini", |
| 1505 L"download", | 1249 "filename=Desktop.ini", |
| 1506 #if defined(OS_WIN) | 1250 "", |
| 1507 L"Setup.exe.download" | 1251 "", |
| 1508 #else | 1252 "application/foo-bar", |
| 1509 L"Setup.exe.lnk" | 1253 L"download", |
| 1510 #endif | 1254 #if defined(OS_WIN) |
| 1511 }, | 1255 L"_Desktop.ini" |
| 1512 { | 1256 #else |
| 1513 __LINE__, | 1257 L"Desktop.ini" |
| 1514 "http://www.badguy.com/Desktop.ini", | 1258 #endif |
| 1515 "filename=Desktop.ini", | 1259 }, |
| 1516 "", | 1260 {__LINE__, |
| 1517 "", | 1261 "http://www.badguy.com/Thumbs.db", |
| 1518 "application/foo-bar", | 1262 "filename=Thumbs.db", |
| 1519 L"download", | 1263 "", |
| 1520 #if defined(OS_WIN) | 1264 "", |
| 1521 L"_Desktop.ini" | 1265 "application/foo-bar", |
| 1522 #else | 1266 L"download", |
| 1523 L"Desktop.ini" | 1267 #if defined(OS_WIN) |
| 1524 #endif | 1268 L"_Thumbs.db" |
| 1525 }, | 1269 #else |
| 1526 { | 1270 L"Thumbs.db" |
| 1527 __LINE__, | 1271 #endif |
| 1528 "http://www.badguy.com/Thumbs.db", | 1272 }, |
| 1529 "filename=Thumbs.db", | 1273 {__LINE__, |
| 1530 "", | 1274 "http://www.hotmail.com", |
| 1531 "", | 1275 "filename=source.jpg", |
| 1532 "application/foo-bar", | 1276 "", |
| 1533 L"download", | 1277 "", |
| 1534 #if defined(OS_WIN) | 1278 "application/x-javascript", |
| 1535 L"_Thumbs.db" | 1279 L"download", |
| 1536 #else | 1280 L"source.jpg"}, |
| 1537 L"Thumbs.db" | 1281 {// http://crbug.com/5772. |
| 1538 #endif | 1282 __LINE__, |
| 1539 }, | 1283 "http://www.example.com/foo.tar.gz", |
| 1540 { | 1284 "", |
| 1541 __LINE__, | 1285 "", |
| 1542 "http://www.hotmail.com", | 1286 "", |
| 1543 "filename=source.jpg", | 1287 "application/x-tar", |
| 1544 "", | 1288 L"download", |
| 1545 "", | 1289 L"foo.tar.gz"}, |
| 1546 "application/x-javascript", | 1290 {// http://crbug.com/52250. |
| 1547 L"download", | 1291 __LINE__, |
| 1548 L"source.jpg" | 1292 "http://www.example.com/foo.tgz", |
| 1549 }, | 1293 "", |
| 1550 { // http://crbug.com/5772. | 1294 "", |
| 1551 __LINE__, | 1295 "", |
| 1552 "http://www.example.com/foo.tar.gz", | 1296 "application/x-tar", |
| 1553 "", | 1297 L"download", |
| 1554 "", | 1298 L"foo.tgz"}, |
| 1555 "", | 1299 {// http://crbug.com/7337. |
| 1556 "application/x-tar", | 1300 __LINE__, |
| 1557 L"download", | 1301 "http://maged.lordaeron.org/blank.reg", |
| 1558 L"foo.tar.gz" | 1302 "", |
| 1559 }, | 1303 "", |
| 1560 { // http://crbug.com/52250. | 1304 "", |
| 1561 __LINE__, | 1305 "text/x-registry", |
| 1562 "http://www.example.com/foo.tgz", | 1306 L"download", |
| 1563 "", | 1307 L"blank.reg"}, |
| 1564 "", | 1308 {__LINE__, |
| 1565 "", | 1309 "http://www.example.com/bar.tar", |
| 1566 "application/x-tar", | 1310 "", |
| 1567 L"download", | 1311 "", |
| 1568 L"foo.tgz" | 1312 "", |
| 1569 }, | 1313 "application/x-tar", |
| 1570 { // http://crbug.com/7337. | 1314 L"download", |
| 1571 __LINE__, | 1315 L"bar.tar"}, |
| 1572 "http://maged.lordaeron.org/blank.reg", | 1316 {__LINE__, |
| 1573 "", | 1317 "http://www.example.com/bar.bogus", |
| 1574 "", | 1318 "", |
| 1575 "", | 1319 "", |
| 1576 "text/x-registry", | 1320 "", |
| 1577 L"download", | 1321 "application/x-tar", |
| 1578 L"blank.reg" | 1322 L"download", |
| 1579 }, | 1323 L"bar.bogus"}, |
| 1580 { | 1324 {// http://crbug.com/20337 |
| 1581 __LINE__, | 1325 __LINE__, |
| 1582 "http://www.example.com/bar.tar", | 1326 "http://www.example.com/.download.txt", |
| 1583 "", | 1327 "filename=.download.txt", |
| 1584 "", | 1328 "", |
| 1585 "", | 1329 "", |
| 1586 "application/x-tar", | 1330 "text/plain", |
| 1587 L"download", | 1331 L"-download", |
| 1588 L"bar.tar" | 1332 L"download.txt"}, |
| 1589 }, | 1333 {// http://crbug.com/56855. |
| 1590 { | 1334 __LINE__, |
| 1591 __LINE__, | 1335 "http://www.example.com/bar.sh", |
| 1592 "http://www.example.com/bar.bogus", | 1336 "", |
| 1593 "", | 1337 "", |
| 1594 "", | 1338 "", |
| 1595 "", | 1339 "application/x-sh", |
| 1596 "application/x-tar", | 1340 L"download", |
| 1597 L"download", | 1341 L"bar.sh"}, |
| 1598 L"bar.bogus" | 1342 {// http://crbug.com/61571 |
| 1599 }, | 1343 __LINE__, |
| 1600 { // http://crbug.com/20337 | 1344 "http://www.example.com/npdf.php?fn=foobar.pdf", |
| 1601 __LINE__, | 1345 "", |
| 1602 "http://www.example.com/.download.txt", | 1346 "", |
| 1603 "filename=.download.txt", | 1347 "", |
| 1604 "", | 1348 "text/plain", |
| 1605 "", | 1349 L"download", |
| 1606 "text/plain", | 1350 L"npdf" TXT_EXT}, |
| 1607 L"-download", | 1351 {// Shouldn't overwrite C-D specified extension. |
| 1608 L"download.txt" | 1352 __LINE__, |
| 1609 }, | 1353 "http://www.example.com/npdf.php?fn=foobar.pdf", |
| 1610 { // http://crbug.com/56855. | 1354 "filename=foobar.jpg", |
| 1611 __LINE__, | 1355 "", |
| 1612 "http://www.example.com/bar.sh", | 1356 "", |
| 1613 "", | 1357 "text/plain", |
| 1614 "", | 1358 L"download", |
| 1615 "", | 1359 L"foobar.jpg"}, |
| 1616 "application/x-sh", | 1360 {// http://crbug.com/87719 |
| 1617 L"download", | 1361 __LINE__, |
| 1618 L"bar.sh" | 1362 "http://www.example.com/image.aspx?id=blargh", |
| 1619 }, | 1363 "", |
| 1620 { // http://crbug.com/61571 | 1364 "", |
| 1621 __LINE__, | 1365 "", |
| 1622 "http://www.example.com/npdf.php?fn=foobar.pdf", | 1366 "image/jpeg", |
| 1623 "", | 1367 L"download", |
| 1624 "", | 1368 L"image" JPEG_EXT}, |
| 1625 "", | |
| 1626 "text/plain", | |
| 1627 L"download", | |
| 1628 L"npdf" TXT_EXT | |
| 1629 }, | |
| 1630 { // Shouldn't overwrite C-D specified extension. | |
| 1631 __LINE__, | |
| 1632 "http://www.example.com/npdf.php?fn=foobar.pdf", | |
| 1633 "filename=foobar.jpg", | |
| 1634 "", | |
| 1635 "", | |
| 1636 "text/plain", | |
| 1637 L"download", | |
| 1638 L"foobar.jpg" | |
| 1639 }, | |
| 1640 { // http://crbug.com/87719 | |
| 1641 __LINE__, | |
| 1642 "http://www.example.com/image.aspx?id=blargh", | |
| 1643 "", | |
| 1644 "", | |
| 1645 "", | |
| 1646 "image/jpeg", | |
| 1647 L"download", | |
| 1648 L"image" JPEG_EXT | |
| 1649 }, | |
| 1650 #if defined(OS_CHROMEOS) | 1369 #if defined(OS_CHROMEOS) |
| 1651 { // http://crosbug.com/26028 | 1370 {// http://crosbug.com/26028 |
| 1652 __LINE__, | 1371 __LINE__, |
| 1653 "http://www.example.com/fooa%cc%88.txt", | 1372 "http://www.example.com/fooa%cc%88.txt", |
| 1654 "", | 1373 "", |
| 1655 "", | 1374 "", |
| 1656 "", | 1375 "", |
| 1657 "image/jpeg", | 1376 "image/jpeg", |
| 1658 L"foo\xe4", | 1377 L"foo\xe4", |
| 1659 L"foo\xe4.txt" | 1378 L"foo\xe4.txt"}, |
| 1660 }, | |
| 1661 #endif | 1379 #endif |
| 1662 }; | 1380 }; |
| 1663 | 1381 |
| 1664 for (size_t i = 0; i < arraysize(selection_tests); ++i) | 1382 for (size_t i = 0; i < arraysize(selection_tests); ++i) |
| 1665 RunGenerateFileNameTestCase(&selection_tests[i]); | 1383 RunGenerateFileNameTestCase(&selection_tests[i]); |
| 1666 | 1384 |
| 1667 for (size_t i = 0; i < arraysize(generation_tests); ++i) | 1385 for (size_t i = 0; i < arraysize(generation_tests); ++i) |
| 1668 RunGenerateFileNameTestCase(&generation_tests[i]); | 1386 RunGenerateFileNameTestCase(&generation_tests[i]); |
| 1669 | 1387 |
| 1670 for (size_t i = 0; i < arraysize(generation_tests); ++i) { | 1388 for (size_t i = 0; i < arraysize(generation_tests); ++i) { |
| 1671 GenerateFilenameCase test_case = generation_tests[i]; | 1389 GenerateFilenameCase test_case = generation_tests[i]; |
| 1672 test_case.referrer_charset = "GBK"; | 1390 test_case.referrer_charset = "GBK"; |
| 1673 RunGenerateFileNameTestCase(&test_case); | 1391 RunGenerateFileNameTestCase(&test_case); |
| 1674 } | 1392 } |
| 1675 } | 1393 } |
| 1676 | 1394 |
| 1677 } // namespace net | 1395 } // namespace net |
| OLD | NEW |