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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 test_case->referrer_charset, test_case->suggested_filename, | 74 test_case->referrer_charset, test_case->suggested_filename, |
75 test_case->mime_type, default_filename); | 75 test_case->mime_type, default_filename); |
76 EXPECT_EQ(test_case->expected_filename, FilePathAsWString(file_path)) | 76 EXPECT_EQ(test_case->expected_filename, FilePathAsWString(file_path)) |
77 << "test case at line number: " << test_case->lineno << "; " | 77 << "test case at line number: " << test_case->lineno << "; " |
78 << GetLocaleWarningString(); | 78 << GetLocaleWarningString(); |
79 } | 79 } |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 static const base::FilePath::CharType* kSafePortableBasenames[] = { | 83 static const base::FilePath::CharType* kSafePortableBasenames[] = { |
84 FILE_PATH_LITERAL("a"), | 84 FILE_PATH_LITERAL("a"), |
85 FILE_PATH_LITERAL("a.txt"), | 85 FILE_PATH_LITERAL("a.txt"), |
86 FILE_PATH_LITERAL("a b.txt"), | 86 FILE_PATH_LITERAL("a b.txt"), |
87 FILE_PATH_LITERAL("a-b.txt"), | 87 FILE_PATH_LITERAL("a-b.txt"), |
88 FILE_PATH_LITERAL("My Computer"), | 88 FILE_PATH_LITERAL("My Computer"), |
89 FILE_PATH_LITERAL(" Computer"), | |
90 }; | 89 }; |
91 | 90 |
92 static const base::FilePath::CharType* kUnsafePortableBasenames[] = { | 91 static const base::FilePath::CharType* kUnsafePortableBasenames[] = { |
93 FILE_PATH_LITERAL(""), | 92 FILE_PATH_LITERAL(""), |
94 FILE_PATH_LITERAL("."), | 93 FILE_PATH_LITERAL("."), |
95 FILE_PATH_LITERAL(".."), | 94 FILE_PATH_LITERAL(".."), |
96 FILE_PATH_LITERAL("..."), | 95 FILE_PATH_LITERAL("..."), |
97 FILE_PATH_LITERAL("con"), | 96 FILE_PATH_LITERAL("con"), |
98 FILE_PATH_LITERAL("con.zip"), | 97 FILE_PATH_LITERAL("con.zip"), |
99 FILE_PATH_LITERAL("NUL"), | 98 FILE_PATH_LITERAL("NUL"), |
100 FILE_PATH_LITERAL("NUL.zip"), | 99 FILE_PATH_LITERAL("NUL.zip"), |
101 FILE_PATH_LITERAL(".a"), | 100 FILE_PATH_LITERAL(".a"), |
102 FILE_PATH_LITERAL("a."), | 101 FILE_PATH_LITERAL("a."), |
103 FILE_PATH_LITERAL("a\"a"), | 102 FILE_PATH_LITERAL("a\"a"), |
104 FILE_PATH_LITERAL("a<a"), | 103 FILE_PATH_LITERAL("a<a"), |
105 FILE_PATH_LITERAL("a>a"), | 104 FILE_PATH_LITERAL("a>a"), |
106 FILE_PATH_LITERAL("a?a"), | 105 FILE_PATH_LITERAL("a?a"), |
107 FILE_PATH_LITERAL("a/"), | 106 FILE_PATH_LITERAL("a/"), |
108 FILE_PATH_LITERAL("a\\"), | 107 FILE_PATH_LITERAL("a\\"), |
109 FILE_PATH_LITERAL("a "), | 108 FILE_PATH_LITERAL("a "), |
110 FILE_PATH_LITERAL("a . ."), | 109 FILE_PATH_LITERAL("a . ."), |
111 FILE_PATH_LITERAL("My Computer.{a}"), | 110 FILE_PATH_LITERAL(" Computer"), |
112 FILE_PATH_LITERAL("My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), | 111 FILE_PATH_LITERAL("My Computer.{a}"), |
| 112 FILE_PATH_LITERAL("My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}"), |
113 #if !defined(OS_WIN) | 113 #if !defined(OS_WIN) |
114 FILE_PATH_LITERAL("a\\a"), | 114 FILE_PATH_LITERAL("a\\a"), |
115 #endif | 115 #endif |
116 }; | 116 }; |
117 | 117 |
118 static const base::FilePath::CharType* kSafePortableRelativePaths[] = { | 118 static const base::FilePath::CharType* kSafePortableRelativePaths[] = { |
119 FILE_PATH_LITERAL("a/a"), | 119 FILE_PATH_LITERAL("a/a"), |
120 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
121 FILE_PATH_LITERAL("a\\a"), | 121 FILE_PATH_LITERAL("a\\a"), |
122 #endif | 122 #endif |
123 }; | 123 }; |
124 | 124 |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 L"download", | 945 L"download", |
946 L"download" JPEG_EXT | 946 L"download" JPEG_EXT |
947 }, | 947 }, |
948 }; | 948 }; |
949 | 949 |
950 // Tests filename generation. Once the correct filename is | 950 // Tests filename generation. Once the correct filename is |
951 // selected, they should be passed through the validation steps and | 951 // selected, they should be passed through the validation steps and |
952 // a correct extension should be added if necessary. | 952 // a correct extension should be added if necessary. |
953 const GenerateFilenameCase generation_tests[] = { | 953 const GenerateFilenameCase generation_tests[] = { |
954 // Dotfiles. Ensures preceeding period(s) stripped. | 954 // Dotfiles. Ensures preceeding period(s) stripped. |
955 { | 955 {__LINE__, |
956 __LINE__, | 956 "http://www.google.com/.test.html", |
957 "http://www.google.com/.test.html", | 957 "", |
958 "", | 958 "", |
959 "", | 959 "", |
960 "", | 960 "", |
961 "", | 961 L"", |
962 L"", | 962 L"test.html"}, |
963 L"test.html" | 963 {__LINE__, "http://www.google.com/.test", "", "", "", "", L"", L"test"}, |
964 }, | 964 {__LINE__, "http://www.google.com/..test", "", "", "", "", L"", L"test"}, |
965 { | 965 {// Disposition has relative paths, remove directory separators |
966 __LINE__, | 966 __LINE__, |
967 "http://www.google.com/.test", | 967 "http://www.evil.com/my_download.txt", |
968 "", | 968 "filename=../../../../././../a_file_name.txt", |
969 "", | 969 "", |
970 "", | 970 "", |
971 "", | 971 "text/plain", |
972 L"", | 972 L"download", |
973 L"test" | 973 L"-..-..-..-.-.-..-a_file_name.txt"}, |
974 }, | 974 {// Disposition has parent directories, remove directory separators |
975 { | 975 __LINE__, |
976 __LINE__, | 976 "http://www.evil.com/my_download.txt", |
977 "http://www.google.com/..test", | 977 "filename=dir1/dir2/a_file_name.txt", |
978 "", | 978 "", |
979 "", | 979 "", |
980 "", | 980 "text/plain", |
981 "", | 981 L"download", |
982 L"", | 982 L"dir1-dir2-a_file_name.txt"}, |
983 L"test" | 983 {// Disposition has relative paths, remove directory separators |
984 }, | 984 __LINE__, |
985 { // Disposition has relative paths, remove directory separators | 985 "http://www.evil.com/my_download.txt", |
986 __LINE__, | 986 "filename=..\\..\\..\\..\\.\\.\\..\\a_file_name.txt", |
987 "http://www.evil.com/my_download.txt", | 987 "", |
988 "filename=../../../../././../a_file_name.txt", | 988 "", |
989 "", | 989 "text/plain", |
990 "", | 990 L"download", |
991 "text/plain", | 991 L"-..-..-..-.-.-..-a_file_name.txt"}, |
992 L"download", | 992 {// Disposition has parent directories, remove directory separators |
993 L"-..-..-..-.-.-..-a_file_name.txt" | 993 __LINE__, |
994 }, | 994 "http://www.evil.com/my_download.txt", |
995 { // Disposition has parent directories, remove directory separators | 995 "filename=dir1\\dir2\\a_file_name.txt", |
996 __LINE__, | 996 "", |
997 "http://www.evil.com/my_download.txt", | 997 "", |
998 "filename=dir1/dir2/a_file_name.txt", | 998 "text/plain", |
999 "", | 999 L"download", |
1000 "", | 1000 L"dir1-dir2-a_file_name.txt"}, |
1001 "text/plain", | 1001 {// No useful information in disposition or URL, use default |
1002 L"download", | 1002 __LINE__, |
1003 L"dir1-dir2-a_file_name.txt" | 1003 "http://www.truncated.com/path/", |
1004 }, | 1004 "", |
1005 { // Disposition has relative paths, remove directory separators | 1005 "", |
1006 __LINE__, | 1006 "", |
1007 "http://www.evil.com/my_download.txt", | 1007 "text/plain", |
1008 "filename=..\\..\\..\\..\\.\\.\\..\\a_file_name.txt", | 1008 L"download", |
1009 "", | 1009 L"download" TXT_EXT}, |
1010 "", | 1010 {// Filename looks like HTML? |
1011 "text/plain", | 1011 __LINE__, |
1012 L"download", | 1012 "http://www.evil.com/get/malware/here", |
1013 L"-..-..-..-.-.-..-a_file_name.txt" | 1013 "filename=\"<blink>Hello kitty</blink>\"", |
1014 }, | 1014 "", |
1015 { // Disposition has parent directories, remove directory separators | 1015 "", |
1016 __LINE__, | 1016 "text/plain", |
1017 "http://www.evil.com/my_download.txt", | 1017 L"default", |
1018 "filename=dir1\\dir2\\a_file_name.txt", | 1018 L"-blink-Hello kitty--blink-"}, |
1019 "", | 1019 {// A normal avi should get .avi and not .avi.avi |
1020 "", | 1020 __LINE__, |
1021 "text/plain", | 1021 "https://blah.google.com/misc/2.avi", |
1022 L"download", | 1022 "", |
1023 L"dir1-dir2-a_file_name.txt" | 1023 "", |
1024 }, | 1024 "", |
1025 { // No useful information in disposition or URL, use default | 1025 "video/x-msvideo", |
1026 __LINE__, | 1026 L"download", |
1027 "http://www.truncated.com/path/", | 1027 L"2.avi"}, |
1028 "", | 1028 {// Extension generation |
1029 "", | 1029 __LINE__, |
1030 "", | 1030 "http://www.example.com/my-cat", |
1031 "text/plain", | 1031 "filename=my-cat", |
1032 L"download", | 1032 "", |
1033 L"download" TXT_EXT | 1033 "", |
1034 }, | 1034 "image/jpeg", |
1035 { // Filename looks like HTML? | 1035 L"download", |
1036 __LINE__, | 1036 L"my-cat"}, |
1037 "http://www.evil.com/get/malware/here", | 1037 {__LINE__, |
1038 "filename=\"<blink>Hello kitty</blink>\"", | 1038 "http://www.example.com/my-cat", |
1039 "", | 1039 "filename=my-cat", |
1040 "", | 1040 "", |
1041 "text/plain", | 1041 "", |
1042 L"default", | 1042 "text/plain", |
1043 L"-blink-Hello kitty--blink-" | 1043 L"download", |
1044 }, | 1044 L"my-cat"}, |
1045 { // A normal avi should get .avi and not .avi.avi | 1045 {__LINE__, |
1046 __LINE__, | 1046 "http://www.example.com/my-cat", |
1047 "https://blah.google.com/misc/2.avi", | 1047 "filename=my-cat", |
1048 "", | 1048 "", |
1049 "", | 1049 "", |
1050 "", | 1050 "text/html", |
1051 "video/x-msvideo", | 1051 L"download", |
1052 L"download", | 1052 L"my-cat"}, |
1053 L"2.avi" | 1053 {// Unknown MIME type |
1054 }, | 1054 __LINE__, |
1055 { // Extension generation | 1055 "http://www.example.com/my-cat", |
1056 __LINE__, | 1056 "filename=my-cat", |
1057 "http://www.example.com/my-cat", | 1057 "", |
1058 "filename=my-cat", | 1058 "", |
1059 "", | 1059 "dance/party", |
1060 "", | 1060 L"download", |
1061 "image/jpeg", | 1061 L"my-cat"}, |
1062 L"download", | 1062 {__LINE__, |
1063 L"my-cat" | 1063 "http://www.example.com/my-cat.jpg", |
1064 }, | 1064 "filename=my-cat.jpg", |
1065 { | 1065 "", |
1066 __LINE__, | 1066 "", |
1067 "http://www.example.com/my-cat", | 1067 "text/plain", |
1068 "filename=my-cat", | 1068 L"download", |
1069 "", | 1069 L"my-cat.jpg"}, |
1070 "", | |
1071 "text/plain", | |
1072 L"download", | |
1073 L"my-cat" | |
1074 }, | |
1075 { | |
1076 __LINE__, | |
1077 "http://www.example.com/my-cat", | |
1078 "filename=my-cat", | |
1079 "", | |
1080 "", | |
1081 "text/html", | |
1082 L"download", | |
1083 L"my-cat" | |
1084 }, | |
1085 { // Unknown MIME type | |
1086 __LINE__, | |
1087 "http://www.example.com/my-cat", | |
1088 "filename=my-cat", | |
1089 "", | |
1090 "", | |
1091 "dance/party", | |
1092 L"download", | |
1093 L"my-cat" | |
1094 }, | |
1095 { | |
1096 __LINE__, | |
1097 "http://www.example.com/my-cat.jpg", | |
1098 "filename=my-cat.jpg", | |
1099 "", | |
1100 "", | |
1101 "text/plain", | |
1102 L"download", | |
1103 L"my-cat.jpg" | |
1104 }, | |
1105 // Windows specific tests | 1070 // Windows specific tests |
1106 #if defined(OS_WIN) | 1071 #if defined(OS_WIN) |
1107 { | 1072 {__LINE__, |
1108 __LINE__, | 1073 "http://www.goodguy.com/evil.exe", |
1109 "http://www.goodguy.com/evil.exe", | 1074 "filename=evil.exe", |
1110 "filename=evil.exe", | 1075 "", |
1111 "", | 1076 "", |
1112 "", | 1077 "image/jpeg", |
1113 "image/jpeg", | 1078 L"download", |
1114 L"download", | 1079 L"evil.exe"}, |
1115 L"evil.exe" | 1080 {__LINE__, |
1116 }, | 1081 "http://www.goodguy.com/ok.exe", |
1117 { | 1082 "filename=ok.exe", |
1118 __LINE__, | 1083 "", |
1119 "http://www.goodguy.com/ok.exe", | 1084 "", |
1120 "filename=ok.exe", | 1085 "binary/octet-stream", |
1121 "", | 1086 L"download", |
1122 "", | 1087 L"ok.exe"}, |
1123 "binary/octet-stream", | 1088 {__LINE__, |
1124 L"download", | 1089 "http://www.goodguy.com/evil.dll", |
1125 L"ok.exe" | 1090 "filename=evil.dll", |
1126 }, | 1091 "", |
1127 { | 1092 "", |
1128 __LINE__, | 1093 "dance/party", |
1129 "http://www.goodguy.com/evil.dll", | 1094 L"download", |
1130 "filename=evil.dll", | 1095 L"evil.dll"}, |
1131 "", | 1096 {__LINE__, |
1132 "", | 1097 "http://www.goodguy.com/evil.exe", |
1133 "dance/party", | 1098 "filename=evil", |
1134 L"download", | 1099 "", |
1135 L"evil.dll" | 1100 "", |
1136 }, | 1101 "application/rss+xml", |
1137 { | 1102 L"download", |
1138 __LINE__, | 1103 L"evil"}, |
1139 "http://www.goodguy.com/evil.exe", | |
1140 "filename=evil", | |
1141 "", | |
1142 "", | |
1143 "application/rss+xml", | |
1144 L"download", | |
1145 L"evil" | |
1146 }, | |
1147 // Test truncation of trailing dots and spaces | 1104 // Test truncation of trailing dots and spaces |
1148 { | 1105 {__LINE__, |
1149 __LINE__, | 1106 "http://www.goodguy.com/evil.exe ", |
1150 "http://www.goodguy.com/evil.exe ", | 1107 "filename=evil.exe ", |
1151 "filename=evil.exe ", | 1108 "", |
1152 "", | 1109 "", |
1153 "", | 1110 "binary/octet-stream", |
1154 "binary/octet-stream", | 1111 L"download", |
1155 L"download", | 1112 L"evil.exe"}, |
1156 L"evil.exe" | 1113 {__LINE__, |
1157 }, | 1114 "http://www.goodguy.com/evil.exe.", |
1158 { | 1115 "filename=evil.exe.", |
1159 __LINE__, | 1116 "", |
1160 "http://www.goodguy.com/evil.exe.", | 1117 "", |
1161 "filename=evil.exe.", | 1118 "binary/octet-stream", |
1162 "", | 1119 L"download", |
1163 "", | 1120 L"evil.exe-"}, |
1164 "binary/octet-stream", | 1121 {__LINE__, |
1165 L"download", | 1122 "http://www.goodguy.com/evil.exe. . .", |
1166 L"evil.exe-" | 1123 "filename=evil.exe. . .", |
1167 }, | 1124 "", |
1168 { | 1125 "", |
1169 __LINE__, | 1126 "binary/octet-stream", |
1170 "http://www.goodguy.com/evil.exe. . .", | 1127 L"download", |
1171 "filename=evil.exe. . .", | 1128 L"evil.exe-------"}, |
1172 "", | 1129 {__LINE__, |
1173 "", | 1130 "http://www.goodguy.com/evil.", |
1174 "binary/octet-stream", | 1131 "filename=evil.", |
1175 L"download", | 1132 "", |
1176 L"evil.exe-------" | 1133 "", |
1177 }, | 1134 "binary/octet-stream", |
1178 { | 1135 L"download", |
1179 __LINE__, | 1136 L"evil-"}, |
1180 "http://www.goodguy.com/evil.", | 1137 {__LINE__, |
1181 "filename=evil.", | 1138 "http://www.goodguy.com/. . . . .", |
1182 "", | 1139 "filename=. . . . .", |
1183 "", | 1140 "", |
1184 "binary/octet-stream", | 1141 "", |
1185 L"download", | 1142 "binary/octet-stream", |
1186 L"evil-" | 1143 L"download", |
1187 }, | 1144 L"download"}, |
1188 { | 1145 {__LINE__, |
1189 __LINE__, | 1146 "http://www.badguy.com/attachment?name=meh.exe%C2%A0", |
1190 "http://www.goodguy.com/. . . . .", | 1147 "attachment; filename=\"meh.exe\xC2\xA0\"", |
1191 "filename=. . . . .", | 1148 "", |
1192 "", | 1149 "", |
1193 "", | 1150 "binary/octet-stream", |
1194 "binary/octet-stream", | 1151 L"", |
1195 L"download", | 1152 L"meh.exe-"}, |
1196 L"download" | |
1197 }, | |
1198 { | |
1199 __LINE__, | |
1200 "http://www.badguy.com/attachment?name=meh.exe%C2%A0", | |
1201 "attachment; filename=\"meh.exe\xC2\xA0\"", | |
1202 "", | |
1203 "", | |
1204 "binary/octet-stream", | |
1205 L"", | |
1206 L"meh.exe-" | |
1207 }, | |
1208 #endif // OS_WIN | 1153 #endif // OS_WIN |
1209 { | 1154 {__LINE__, |
1210 __LINE__, | 1155 "http://www.goodguy.com/utils.js", |
1211 "http://www.goodguy.com/utils.js", | 1156 "filename=utils.js", |
1212 "filename=utils.js", | 1157 "", |
1213 "", | 1158 "", |
1214 "", | 1159 "application/x-javascript", |
1215 "application/x-javascript", | 1160 L"download", |
1216 L"download", | 1161 L"utils.js"}, |
1217 L"utils.js" | 1162 {__LINE__, |
1218 }, | 1163 "http://www.goodguy.com/contacts.js", |
1219 { | 1164 "filename=contacts.js", |
1220 __LINE__, | 1165 "", |
1221 "http://www.goodguy.com/contacts.js", | 1166 "", |
1222 "filename=contacts.js", | 1167 "application/json", |
1223 "", | 1168 L"download", |
1224 "", | 1169 L"contacts.js"}, |
1225 "application/json", | 1170 {__LINE__, |
1226 L"download", | 1171 "http://www.goodguy.com/utils.js", |
1227 L"contacts.js" | 1172 "filename=utils.js", |
1228 }, | 1173 "", |
1229 { | 1174 "", |
1230 __LINE__, | 1175 "text/javascript", |
1231 "http://www.goodguy.com/utils.js", | 1176 L"download", |
1232 "filename=utils.js", | 1177 L"utils.js"}, |
1233 "", | 1178 {__LINE__, |
1234 "", | 1179 "http://www.goodguy.com/utils.js", |
1235 "text/javascript", | 1180 "filename=utils.js", |
1236 L"download", | 1181 "", |
1237 L"utils.js" | 1182 "", |
1238 }, | 1183 "text/javascript;version=2", |
1239 { | 1184 L"download", |
1240 __LINE__, | 1185 L"utils.js"}, |
1241 "http://www.goodguy.com/utils.js", | 1186 {__LINE__, |
1242 "filename=utils.js", | 1187 "http://www.goodguy.com/utils.js", |
1243 "", | 1188 "filename=utils.js", |
1244 "", | 1189 "", |
1245 "text/javascript;version=2", | 1190 "", |
1246 L"download", | 1191 "application/ecmascript", |
1247 L"utils.js" | 1192 L"download", |
1248 }, | 1193 L"utils.js"}, |
1249 { | 1194 {__LINE__, |
1250 __LINE__, | 1195 "http://www.goodguy.com/utils.js", |
1251 "http://www.goodguy.com/utils.js", | 1196 "filename=utils.js", |
1252 "filename=utils.js", | 1197 "", |
1253 "", | 1198 "", |
1254 "", | 1199 "application/ecmascript;version=4", |
1255 "application/ecmascript", | 1200 L"download", |
1256 L"download", | 1201 L"utils.js"}, |
1257 L"utils.js" | 1202 {__LINE__, |
1258 }, | 1203 "http://www.goodguy.com/program.exe", |
1259 { | 1204 "filename=program.exe", |
1260 __LINE__, | 1205 "", |
1261 "http://www.goodguy.com/utils.js", | 1206 "", |
1262 "filename=utils.js", | 1207 "application/foo-bar", |
1263 "", | 1208 L"download", |
1264 "", | 1209 L"program.exe"}, |
1265 "application/ecmascript;version=4", | 1210 {__LINE__, |
1266 L"download", | 1211 "http://www.evil.com/../foo.txt", |
1267 L"utils.js" | 1212 "filename=../foo.txt", |
1268 }, | 1213 "", |
1269 { | 1214 "", |
1270 __LINE__, | 1215 "text/plain", |
1271 "http://www.goodguy.com/program.exe", | 1216 L"download", |
1272 "filename=program.exe", | 1217 L"-foo.txt"}, |
1273 "", | 1218 {__LINE__, |
1274 "", | 1219 "http://www.evil.com/..\\foo.txt", |
1275 "application/foo-bar", | 1220 "filename=..\\foo.txt", |
1276 L"download", | 1221 "", |
1277 L"program.exe" | 1222 "", |
1278 }, | 1223 "text/plain", |
1279 { | 1224 L"download", |
1280 __LINE__, | 1225 L"-foo.txt"}, |
1281 "http://www.evil.com/../foo.txt", | 1226 {__LINE__, |
1282 "filename=../foo.txt", | 1227 "http://www.evil.com/.hidden", |
1283 "", | 1228 "filename=.hidden", |
1284 "", | 1229 "", |
1285 "text/plain", | 1230 "", |
1286 L"download", | 1231 "text/plain", |
1287 L"-foo.txt" | 1232 L"download", |
1288 }, | 1233 L"hidden"}, |
1289 { | 1234 {__LINE__, |
1290 __LINE__, | 1235 "http://www.evil.com/trailing.", |
1291 "http://www.evil.com/..\\foo.txt", | 1236 "filename=trailing.", |
1292 "filename=..\\foo.txt", | 1237 "", |
1293 "", | 1238 "", |
1294 "", | 1239 "dance/party", |
1295 "text/plain", | 1240 L"download", |
1296 L"download", | 1241 #if defined(OS_WIN) |
1297 L"-foo.txt" | 1242 L"trailing-" |
1298 }, | 1243 #else |
1299 { | 1244 L"trailing" |
1300 __LINE__, | 1245 #endif |
1301 "http://www.evil.com/.hidden", | 1246 }, |
1302 "filename=.hidden", | 1247 {__LINE__, |
1303 "", | 1248 "http://www.evil.com/trailing.", |
1304 "", | 1249 "filename=trailing.", |
1305 "text/plain", | 1250 "", |
1306 L"download", | 1251 "", |
1307 L"hidden" | 1252 "text/plain", |
1308 }, | 1253 L"download", |
1309 { | 1254 #if defined(OS_WIN) |
1310 __LINE__, | 1255 L"trailing-" |
1311 "http://www.evil.com/trailing.", | 1256 #else |
1312 "filename=trailing.", | 1257 L"trailing" |
1313 "", | 1258 #endif |
1314 "", | 1259 }, |
1315 "dance/party", | 1260 {__LINE__, |
1316 L"download", | 1261 "http://www.evil.com/.", |
1317 #if defined(OS_WIN) | 1262 "filename=.", |
1318 L"trailing-" | 1263 "", |
1319 #else | 1264 "", |
1320 L"trailing" | 1265 "dance/party", |
1321 #endif | 1266 L"download", |
1322 }, | 1267 L"download"}, |
1323 { | 1268 {__LINE__, |
1324 __LINE__, | 1269 "http://www.evil.com/..", |
1325 "http://www.evil.com/trailing.", | 1270 "filename=..", |
1326 "filename=trailing.", | 1271 "", |
1327 "", | 1272 "", |
1328 "", | 1273 "dance/party", |
1329 "text/plain", | 1274 L"download", |
1330 L"download", | 1275 L"download"}, |
1331 #if defined(OS_WIN) | 1276 {__LINE__, |
1332 L"trailing-" | 1277 "http://www.evil.com/...", |
1333 #else | 1278 "filename=...", |
1334 L"trailing" | 1279 "", |
1335 #endif | 1280 "", |
1336 }, | 1281 "dance/party", |
1337 { | 1282 L"download", |
1338 __LINE__, | 1283 L"download"}, |
1339 "http://www.evil.com/.", | 1284 {// Note that this one doesn't have "filename=" on it. |
1340 "filename=.", | 1285 __LINE__, |
1341 "", | 1286 "http://www.evil.com/", |
1342 "", | 1287 "a_file_name.txt", |
1343 "dance/party", | 1288 "", |
1344 L"download", | 1289 "", |
1345 L"download" | 1290 "image/jpeg", |
1346 }, | 1291 L"download", |
1347 { | 1292 L"download" JPEG_EXT}, |
1348 __LINE__, | 1293 {__LINE__, |
1349 "http://www.evil.com/..", | 1294 "http://www.evil.com/", |
1350 "filename=..", | 1295 "filename=", |
1351 "", | 1296 "", |
1352 "", | 1297 "", |
1353 "dance/party", | 1298 "image/jpeg", |
1354 L"download", | 1299 L"download", |
1355 L"download" | 1300 L"download" JPEG_EXT}, |
1356 }, | 1301 {__LINE__, |
1357 { | 1302 "http://www.example.com/simple", |
1358 __LINE__, | 1303 "filename=simple", |
1359 "http://www.evil.com/...", | 1304 "", |
1360 "filename=...", | 1305 "", |
1361 "", | 1306 "application/octet-stream", |
1362 "", | 1307 L"download", |
1363 "dance/party", | 1308 L"simple"}, |
1364 L"download", | |
1365 L"download" | |
1366 }, | |
1367 { // Note that this one doesn't have "filename=" on it. | |
1368 __LINE__, | |
1369 "http://www.evil.com/", | |
1370 "a_file_name.txt", | |
1371 "", | |
1372 "", | |
1373 "image/jpeg", | |
1374 L"download", | |
1375 L"download" JPEG_EXT | |
1376 }, | |
1377 { | |
1378 __LINE__, | |
1379 "http://www.evil.com/", | |
1380 "filename=", | |
1381 "", | |
1382 "", | |
1383 "image/jpeg", | |
1384 L"download", | |
1385 L"download" JPEG_EXT | |
1386 }, | |
1387 { | |
1388 __LINE__, | |
1389 "http://www.example.com/simple", | |
1390 "filename=simple", | |
1391 "", | |
1392 "", | |
1393 "application/octet-stream", | |
1394 L"download", | |
1395 L"simple" | |
1396 }, | |
1397 // Reserved words on Windows | 1309 // Reserved words on Windows |
1398 { | 1310 {__LINE__, |
1399 __LINE__, | 1311 "http://www.goodguy.com/COM1", |
1400 "http://www.goodguy.com/COM1", | 1312 "filename=COM1", |
1401 "filename=COM1", | 1313 "", |
1402 "", | 1314 "", |
1403 "", | 1315 "application/foo-bar", |
1404 "application/foo-bar", | 1316 L"download", |
1405 L"download", | 1317 #if defined(OS_WIN) |
1406 #if defined(OS_WIN) | 1318 L"_COM1" |
1407 L"_COM1" | 1319 #else |
1408 #else | 1320 L"COM1" |
1409 L"COM1" | 1321 #endif |
1410 #endif | 1322 }, |
1411 }, | 1323 {__LINE__, |
1412 { | 1324 "http://www.goodguy.com/COM4.txt", |
1413 __LINE__, | 1325 "filename=COM4.txt", |
1414 "http://www.goodguy.com/COM4.txt", | 1326 "", |
1415 "filename=COM4.txt", | 1327 "", |
1416 "", | 1328 "text/plain", |
1417 "", | 1329 L"download", |
1418 "text/plain", | 1330 #if defined(OS_WIN) |
1419 L"download", | 1331 L"_COM4.txt" |
1420 #if defined(OS_WIN) | 1332 #else |
1421 L"_COM4.txt" | 1333 L"COM4.txt" |
1422 #else | 1334 #endif |
1423 L"COM4.txt" | 1335 }, |
1424 #endif | 1336 {__LINE__, |
1425 }, | 1337 "http://www.goodguy.com/lpt1.TXT", |
1426 { | 1338 "filename=lpt1.TXT", |
1427 __LINE__, | 1339 "", |
1428 "http://www.goodguy.com/lpt1.TXT", | 1340 "", |
1429 "filename=lpt1.TXT", | 1341 "text/plain", |
1430 "", | 1342 L"download", |
1431 "", | 1343 #if defined(OS_WIN) |
1432 "text/plain", | 1344 L"_lpt1.TXT" |
1433 L"download", | 1345 #else |
1434 #if defined(OS_WIN) | 1346 L"lpt1.TXT" |
1435 L"_lpt1.TXT" | 1347 #endif |
1436 #else | 1348 }, |
1437 L"lpt1.TXT" | 1349 {__LINE__, |
1438 #endif | 1350 "http://www.goodguy.com/clock$.txt", |
1439 }, | 1351 "filename=clock$.txt", |
1440 { | 1352 "", |
1441 __LINE__, | 1353 "", |
1442 "http://www.goodguy.com/clock$.txt", | 1354 "text/plain", |
1443 "filename=clock$.txt", | 1355 L"download", |
1444 "", | 1356 #if defined(OS_WIN) |
1445 "", | 1357 L"_clock$.txt" |
1446 "text/plain", | 1358 #else |
1447 L"download", | 1359 L"clock$.txt" |
1448 #if defined(OS_WIN) | 1360 #endif |
1449 L"_clock$.txt" | 1361 }, |
1450 #else | 1362 {// Validation should also apply to sugested name |
1451 L"clock$.txt" | 1363 __LINE__, |
1452 #endif | 1364 "http://www.goodguy.com/blah$.txt", |
1453 }, | 1365 "filename=clock$.txt", |
1454 { // Validation should also apply to sugested name | 1366 "", |
1455 __LINE__, | 1367 "clock$.txt", |
1456 "http://www.goodguy.com/blah$.txt", | 1368 "text/plain", |
1457 "filename=clock$.txt", | 1369 L"download", |
1458 "", | 1370 #if defined(OS_WIN) |
1459 "clock$.txt", | 1371 L"_clock$.txt" |
1460 "text/plain", | 1372 #else |
1461 L"download", | 1373 L"clock$.txt" |
1462 #if defined(OS_WIN) | 1374 #endif |
1463 L"_clock$.txt" | 1375 }, |
1464 #else | 1376 {__LINE__, |
1465 L"clock$.txt" | 1377 "http://www.goodguy.com/mycom1.foo", |
1466 #endif | 1378 "filename=mycom1.foo", |
1467 }, | 1379 "", |
1468 { | 1380 "", |
1469 __LINE__, | 1381 "text/plain", |
1470 "http://www.goodguy.com/mycom1.foo", | 1382 L"download", |
1471 "filename=mycom1.foo", | 1383 L"mycom1.foo"}, |
1472 "", | 1384 {__LINE__, |
1473 "", | 1385 "http://www.badguy.com/Setup.exe.local", |
1474 "text/plain", | 1386 "filename=Setup.exe.local", |
1475 L"download", | 1387 "", |
1476 L"mycom1.foo" | 1388 "", |
1477 }, | 1389 "application/foo-bar", |
1478 { | 1390 L"download", |
1479 __LINE__, | 1391 #if defined(OS_WIN) |
1480 "http://www.badguy.com/Setup.exe.local", | 1392 L"Setup.exe.download" |
1481 "filename=Setup.exe.local", | 1393 #else |
1482 "", | 1394 L"Setup.exe.local" |
1483 "", | 1395 #endif |
1484 "application/foo-bar", | 1396 }, |
1485 L"download", | 1397 {__LINE__, |
1486 #if defined(OS_WIN) | 1398 "http://www.badguy.com/Setup.exe.local", |
1487 L"Setup.exe.download" | 1399 "filename=Setup.exe.local.local", |
1488 #else | 1400 "", |
1489 L"Setup.exe.local" | 1401 "", |
1490 #endif | 1402 "application/foo-bar", |
1491 }, | 1403 L"download", |
1492 { | 1404 #if defined(OS_WIN) |
1493 __LINE__, | 1405 L"Setup.exe.local.download" |
1494 "http://www.badguy.com/Setup.exe.local", | 1406 #else |
1495 "filename=Setup.exe.local.local", | 1407 L"Setup.exe.local.local" |
1496 "", | 1408 #endif |
1497 "", | 1409 }, |
1498 "application/foo-bar", | 1410 {__LINE__, |
1499 L"download", | 1411 "http://www.badguy.com/Setup.exe.lnk", |
1500 #if defined(OS_WIN) | 1412 "filename=Setup.exe.lnk", |
1501 L"Setup.exe.local.download" | 1413 "", |
1502 #else | 1414 "", |
1503 L"Setup.exe.local.local" | 1415 "application/foo-bar", |
1504 #endif | 1416 L"download", |
1505 }, | 1417 #if defined(OS_WIN) |
1506 { | 1418 L"Setup.exe.download" |
1507 __LINE__, | 1419 #else |
1508 "http://www.badguy.com/Setup.exe.lnk", | 1420 L"Setup.exe.lnk" |
1509 "filename=Setup.exe.lnk", | 1421 #endif |
1510 "", | 1422 }, |
1511 "", | 1423 {__LINE__, |
1512 "application/foo-bar", | 1424 "http://www.badguy.com/Desktop.ini", |
1513 L"download", | 1425 "filename=Desktop.ini", |
1514 #if defined(OS_WIN) | 1426 "", |
1515 L"Setup.exe.download" | 1427 "", |
1516 #else | 1428 "application/foo-bar", |
1517 L"Setup.exe.lnk" | 1429 L"download", |
1518 #endif | 1430 #if defined(OS_WIN) |
1519 }, | 1431 L"_Desktop.ini" |
1520 { | 1432 #else |
1521 __LINE__, | 1433 L"Desktop.ini" |
1522 "http://www.badguy.com/Desktop.ini", | 1434 #endif |
1523 "filename=Desktop.ini", | 1435 }, |
1524 "", | 1436 {__LINE__, |
1525 "", | 1437 "http://www.badguy.com/Thumbs.db", |
1526 "application/foo-bar", | 1438 "filename=Thumbs.db", |
1527 L"download", | 1439 "", |
1528 #if defined(OS_WIN) | 1440 "", |
1529 L"_Desktop.ini" | 1441 "application/foo-bar", |
1530 #else | 1442 L"download", |
1531 L"Desktop.ini" | 1443 #if defined(OS_WIN) |
1532 #endif | 1444 L"_Thumbs.db" |
1533 }, | 1445 #else |
1534 { | 1446 L"Thumbs.db" |
1535 __LINE__, | 1447 #endif |
1536 "http://www.badguy.com/Thumbs.db", | 1448 }, |
1537 "filename=Thumbs.db", | 1449 {__LINE__, |
1538 "", | 1450 "http://www.hotmail.com", |
1539 "", | 1451 "filename=source.jpg", |
1540 "application/foo-bar", | 1452 "", |
1541 L"download", | 1453 "", |
1542 #if defined(OS_WIN) | 1454 "application/x-javascript", |
1543 L"_Thumbs.db" | 1455 L"download", |
1544 #else | 1456 L"source.jpg"}, |
1545 L"Thumbs.db" | 1457 {// http://crbug.com/5772. |
1546 #endif | 1458 __LINE__, |
1547 }, | 1459 "http://www.example.com/foo.tar.gz", |
1548 { | 1460 "", |
1549 __LINE__, | 1461 "", |
1550 "http://www.hotmail.com", | 1462 "", |
1551 "filename=source.jpg", | 1463 "application/x-tar", |
1552 "", | 1464 L"download", |
1553 "", | 1465 L"foo.tar.gz"}, |
1554 "application/x-javascript", | 1466 {// http://crbug.com/52250. |
1555 L"download", | 1467 __LINE__, |
1556 L"source.jpg" | 1468 "http://www.example.com/foo.tgz", |
1557 }, | 1469 "", |
1558 { // http://crbug.com/5772. | 1470 "", |
1559 __LINE__, | 1471 "", |
1560 "http://www.example.com/foo.tar.gz", | 1472 "application/x-tar", |
1561 "", | 1473 L"download", |
1562 "", | 1474 L"foo.tgz"}, |
1563 "", | 1475 {// http://crbug.com/7337. |
1564 "application/x-tar", | 1476 __LINE__, |
1565 L"download", | 1477 "http://maged.lordaeron.org/blank.reg", |
1566 L"foo.tar.gz" | 1478 "", |
1567 }, | 1479 "", |
1568 { // http://crbug.com/52250. | 1480 "", |
1569 __LINE__, | 1481 "text/x-registry", |
1570 "http://www.example.com/foo.tgz", | 1482 L"download", |
1571 "", | 1483 L"blank.reg"}, |
1572 "", | 1484 {__LINE__, |
1573 "", | 1485 "http://www.example.com/bar.tar", |
1574 "application/x-tar", | 1486 "", |
1575 L"download", | 1487 "", |
1576 L"foo.tgz" | 1488 "", |
1577 }, | 1489 "application/x-tar", |
1578 { // http://crbug.com/7337. | 1490 L"download", |
1579 __LINE__, | 1491 L"bar.tar"}, |
1580 "http://maged.lordaeron.org/blank.reg", | 1492 {__LINE__, |
1581 "", | 1493 "http://www.example.com/bar.bogus", |
1582 "", | 1494 "", |
1583 "", | 1495 "", |
1584 "text/x-registry", | 1496 "", |
1585 L"download", | 1497 "application/x-tar", |
1586 L"blank.reg" | 1498 L"download", |
1587 }, | 1499 L"bar.bogus"}, |
1588 { | 1500 {// http://crbug.com/20337 |
1589 __LINE__, | 1501 __LINE__, |
1590 "http://www.example.com/bar.tar", | 1502 "http://www.example.com/.download.txt", |
1591 "", | 1503 "filename=.download.txt", |
1592 "", | 1504 "", |
1593 "", | 1505 "", |
1594 "application/x-tar", | 1506 "text/plain", |
1595 L"download", | 1507 L"-download", |
1596 L"bar.tar" | 1508 L"download.txt"}, |
1597 }, | 1509 {// http://crbug.com/56855. |
1598 { | 1510 __LINE__, |
1599 __LINE__, | 1511 "http://www.example.com/bar.sh", |
1600 "http://www.example.com/bar.bogus", | 1512 "", |
1601 "", | 1513 "", |
1602 "", | 1514 "", |
1603 "", | 1515 "application/x-sh", |
1604 "application/x-tar", | 1516 L"download", |
1605 L"download", | 1517 L"bar.sh"}, |
1606 L"bar.bogus" | 1518 {// http://crbug.com/61571 |
1607 }, | 1519 __LINE__, |
1608 { // http://crbug.com/20337 | 1520 "http://www.example.com/npdf.php?fn=foobar.pdf", |
1609 __LINE__, | 1521 "", |
1610 "http://www.example.com/.download.txt", | 1522 "", |
1611 "filename=.download.txt", | 1523 "", |
1612 "", | 1524 "text/plain", |
1613 "", | 1525 L"download", |
1614 "text/plain", | 1526 L"npdf" TXT_EXT}, |
1615 L"-download", | 1527 {// Shouldn't overwrite C-D specified extension. |
1616 L"download.txt" | 1528 __LINE__, |
1617 }, | 1529 "http://www.example.com/npdf.php?fn=foobar.pdf", |
1618 { // http://crbug.com/56855. | 1530 "filename=foobar.jpg", |
1619 __LINE__, | 1531 "", |
1620 "http://www.example.com/bar.sh", | 1532 "", |
1621 "", | 1533 "text/plain", |
1622 "", | 1534 L"download", |
1623 "", | 1535 L"foobar.jpg"}, |
1624 "application/x-sh", | 1536 {// http://crbug.com/87719 |
1625 L"download", | 1537 __LINE__, |
1626 L"bar.sh" | 1538 "http://www.example.com/image.aspx?id=blargh", |
1627 }, | 1539 "", |
1628 { // http://crbug.com/61571 | 1540 "", |
1629 __LINE__, | 1541 "", |
1630 "http://www.example.com/npdf.php?fn=foobar.pdf", | 1542 "image/jpeg", |
1631 "", | 1543 L"download", |
1632 "", | 1544 L"image" JPEG_EXT}, |
1633 "", | 1545 {__LINE__, |
1634 "text/plain", | 1546 "http://www.example.com/image.aspx?id=blargh", |
1635 L"download", | 1547 "", |
1636 L"npdf" TXT_EXT | 1548 "", |
1637 }, | 1549 " .foo", |
1638 { // Shouldn't overwrite C-D specified extension. | 1550 "", |
1639 __LINE__, | 1551 L"download", |
1640 "http://www.example.com/npdf.php?fn=foobar.pdf", | 1552 L"-.foo"}, |
1641 "filename=foobar.jpg", | |
1642 "", | |
1643 "", | |
1644 "text/plain", | |
1645 L"download", | |
1646 L"foobar.jpg" | |
1647 }, | |
1648 { // http://crbug.com/87719 | |
1649 __LINE__, | |
1650 "http://www.example.com/image.aspx?id=blargh", | |
1651 "", | |
1652 "", | |
1653 "", | |
1654 "image/jpeg", | |
1655 L"download", | |
1656 L"image" JPEG_EXT | |
1657 }, | |
1658 #if defined(OS_CHROMEOS) | 1553 #if defined(OS_CHROMEOS) |
1659 { // http://crosbug.com/26028 | 1554 {// http://crosbug.com/26028 |
1660 __LINE__, | 1555 __LINE__, |
1661 "http://www.example.com/fooa%cc%88.txt", | 1556 "http://www.example.com/fooa%cc%88.txt", |
1662 "", | 1557 "", |
1663 "", | 1558 "", |
1664 "", | 1559 "", |
1665 "image/jpeg", | 1560 "image/jpeg", |
1666 L"foo\xe4", | 1561 L"foo\xe4", |
1667 L"foo\xe4.txt" | 1562 L"foo\xe4.txt"}, |
1668 }, | |
1669 #endif | 1563 #endif |
1670 }; | 1564 }; |
1671 | 1565 |
1672 for (size_t i = 0; i < arraysize(selection_tests); ++i) | 1566 for (size_t i = 0; i < arraysize(selection_tests); ++i) |
1673 RunGenerateFileNameTestCase(&selection_tests[i]); | 1567 RunGenerateFileNameTestCase(&selection_tests[i]); |
1674 | 1568 |
1675 for (size_t i = 0; i < arraysize(generation_tests); ++i) | 1569 for (size_t i = 0; i < arraysize(generation_tests); ++i) |
1676 RunGenerateFileNameTestCase(&generation_tests[i]); | 1570 RunGenerateFileNameTestCase(&generation_tests[i]); |
1677 | 1571 |
1678 for (size_t i = 0; i < arraysize(generation_tests); ++i) { | 1572 for (size_t i = 0; i < arraysize(generation_tests); ++i) { |
1679 GenerateFilenameCase test_case = generation_tests[i]; | 1573 GenerateFilenameCase test_case = generation_tests[i]; |
1680 test_case.referrer_charset = "GBK"; | 1574 test_case.referrer_charset = "GBK"; |
1681 RunGenerateFileNameTestCase(&test_case); | 1575 RunGenerateFileNameTestCase(&test_case); |
1682 } | 1576 } |
1683 } | 1577 } |
1684 | 1578 |
1685 } // namespace net | 1579 } // namespace net |
OLD | NEW |