| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 NetModule::GetResource(IDR_DIR_HEADER_HTML)); | 1088 NetModule::GetResource(IDR_DIR_HEADER_HTML)); |
| 1089 // This can be null in unit tests. | 1089 // This can be null in unit tests. |
| 1090 DLOG_IF(WARNING, header.empty()) << | 1090 DLOG_IF(WARNING, header.empty()) << |
| 1091 "Missing resource: directory listing header"; | 1091 "Missing resource: directory listing header"; |
| 1092 | 1092 |
| 1093 std::string result; | 1093 std::string result; |
| 1094 if (!header.empty()) | 1094 if (!header.empty()) |
| 1095 result.assign(header.data(), header.size()); | 1095 result.assign(header.data(), header.size()); |
| 1096 | 1096 |
| 1097 result.append("<script>start("); | 1097 result.append("<script>start("); |
| 1098 base::JsonDoubleQuote(title, true, &result); | 1098 base::EscapeJSONString(title, true, &result); |
| 1099 result.append(");</script>\n"); | 1099 result.append(");</script>\n"); |
| 1100 | 1100 |
| 1101 return result; | 1101 return result; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 inline bool IsHostCharAlphanumeric(char c) { | 1104 inline bool IsHostCharAlphanumeric(char c) { |
| 1105 // We can just check lowercase because uppercase characters have already been | 1105 // We can just check lowercase because uppercase characters have already been |
| 1106 // normalized. | 1106 // normalized. |
| 1107 return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')); | 1107 return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')); |
| 1108 } | 1108 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 (!desired_tld.empty() && IsHostCharAlphanumeric(desired_tld[0])); | 1142 (!desired_tld.empty() && IsHostCharAlphanumeric(desired_tld[0])); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 std::string GetDirectoryListingEntry(const base::string16& name, | 1145 std::string GetDirectoryListingEntry(const base::string16& name, |
| 1146 const std::string& raw_bytes, | 1146 const std::string& raw_bytes, |
| 1147 bool is_dir, | 1147 bool is_dir, |
| 1148 int64 size, | 1148 int64 size, |
| 1149 Time modified) { | 1149 Time modified) { |
| 1150 std::string result; | 1150 std::string result; |
| 1151 result.append("<script>addRow("); | 1151 result.append("<script>addRow("); |
| 1152 base::JsonDoubleQuote(name, true, &result); | 1152 base::EscapeJSONString(name, true, &result); |
| 1153 result.append(","); | 1153 result.append(","); |
| 1154 if (raw_bytes.empty()) { | 1154 if (raw_bytes.empty()) { |
| 1155 base::JsonDoubleQuote(EscapePath(UTF16ToUTF8(name)), | 1155 base::EscapeJSONString(EscapePath(UTF16ToUTF8(name)), true, &result); |
| 1156 true, &result); | |
| 1157 } else { | 1156 } else { |
| 1158 base::JsonDoubleQuote(EscapePath(raw_bytes), true, &result); | 1157 base::EscapeJSONString(EscapePath(raw_bytes), true, &result); |
| 1159 } | 1158 } |
| 1160 if (is_dir) { | 1159 if (is_dir) { |
| 1161 result.append(",1,"); | 1160 result.append(",1,"); |
| 1162 } else { | 1161 } else { |
| 1163 result.append(",0,"); | 1162 result.append(",0,"); |
| 1164 } | 1163 } |
| 1165 | 1164 |
| 1166 // Negative size means unknown or not applicable (e.g. directory). | 1165 // Negative size means unknown or not applicable (e.g. directory). |
| 1167 base::string16 size_string; | 1166 base::string16 size_string; |
| 1168 if (size >= 0) | 1167 if (size >= 0) |
| 1169 size_string = FormatBytesUnlocalized(size); | 1168 size_string = FormatBytesUnlocalized(size); |
| 1170 base::JsonDoubleQuote(size_string, true, &result); | 1169 base::EscapeJSONString(size_string, true, &result); |
| 1171 | 1170 |
| 1172 result.append(","); | 1171 result.append(","); |
| 1173 | 1172 |
| 1174 base::string16 modified_str; | 1173 base::string16 modified_str; |
| 1175 // |modified| can be NULL in FTP listings. | 1174 // |modified| can be NULL in FTP listings. |
| 1176 if (!modified.is_null()) { | 1175 if (!modified.is_null()) { |
| 1177 modified_str = base::TimeFormatShortDateAndTime(modified); | 1176 modified_str = base::TimeFormatShortDateAndTime(modified); |
| 1178 } | 1177 } |
| 1179 base::JsonDoubleQuote(modified_str, true, &result); | 1178 base::EscapeJSONString(modified_str, true, &result); |
| 1180 | 1179 |
| 1181 result.append(");</script>\n"); | 1180 result.append(");</script>\n"); |
| 1182 | 1181 |
| 1183 return result; | 1182 return result; |
| 1184 } | 1183 } |
| 1185 | 1184 |
| 1186 base::string16 StripWWW(const base::string16& text) { | 1185 base::string16 StripWWW(const base::string16& text) { |
| 1187 const base::string16 www(ASCIIToUTF16("www.")); | 1186 const base::string16 www(ASCIIToUTF16("www.")); |
| 1188 return StartsWith(text, www, true) ? text.substr(www.length()) : text; | 1187 return StartsWith(text, www, true) ? text.substr(www.length()) : text; |
| 1189 } | 1188 } |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2214 } | 2213 } |
| 2215 return a1.size() * CHAR_BIT; | 2214 return a1.size() * CHAR_BIT; |
| 2216 } | 2215 } |
| 2217 | 2216 |
| 2218 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 2217 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
| 2219 IPAddressNumber all_ones(mask.size(), 0xFF); | 2218 IPAddressNumber all_ones(mask.size(), 0xFF); |
| 2220 return CommonPrefixLength(mask, all_ones); | 2219 return CommonPrefixLength(mask, all_ones); |
| 2221 } | 2220 } |
| 2222 | 2221 |
| 2223 } // namespace net | 2222 } // namespace net |
| OLD | NEW |