Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: net/ftp/ftp_directory_listing_parser.cc

Issue 2613093003: Landing again: "Make FTP directory parser less strict" (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ftp/ftp_directory_listing_parser.h" 5 #include "net/ftp/ftp_directory_listing_parser.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/i18n/encoding_detection.h" 9 #include "base/i18n/encoding_detection.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
(...skipping 10 matching lines...) Expand all
21 namespace net { 21 namespace net {
22 22
23 namespace { 23 namespace {
24 24
25 // Fills in |raw_name| for all |entries| using |encoding|. Returns network 25 // Fills in |raw_name| for all |entries| using |encoding|. Returns network
26 // error code. 26 // error code.
27 int FillInRawName(const std::string& encoding, 27 int FillInRawName(const std::string& encoding,
28 std::vector<FtpDirectoryListingEntry>* entries) { 28 std::vector<FtpDirectoryListingEntry>* entries) {
29 for (size_t i = 0; i < entries->size(); i++) { 29 for (size_t i = 0; i < entries->size(); i++) {
30 if (!base::UTF16ToCodepage(entries->at(i).name, encoding.c_str(), 30 if (!base::UTF16ToCodepage(entries->at(i).name, encoding.c_str(),
31 base::OnStringConversionError::FAIL, 31 base::OnStringConversionError::SUBSTITUTE,
32 &entries->at(i).raw_name)) { 32 &entries->at(i).raw_name)) {
33 return ERR_ENCODING_CONVERSION_FAILED; 33 return ERR_ENCODING_CONVERSION_FAILED;
34 } 34 }
35 } 35 }
36 36
37 return OK; 37 return OK;
38 } 38 }
39 39
40 // Parses |text| as an FTP directory listing. Fills in |entries| 40 // Parses |text| as an FTP directory listing. Fills in |entries|
41 // and |server_type| and returns network error code. 41 // and |server_type| and returns network error code.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const base::Time& current_time, 84 const base::Time& current_time,
85 std::vector<FtpDirectoryListingEntry>* entries, 85 std::vector<FtpDirectoryListingEntry>* entries,
86 FtpServerType* server_type) { 86 FtpServerType* server_type) {
87 std::string encoding; 87 std::string encoding;
88 if (!base::DetectEncoding(text, &encoding)) 88 if (!base::DetectEncoding(text, &encoding))
89 return ERR_ENCODING_DETECTION_FAILED; 89 return ERR_ENCODING_DETECTION_FAILED;
90 const char* encoding_name = encoding.c_str(); 90 const char* encoding_name = encoding.c_str();
91 91
92 base::string16 converted_text; 92 base::string16 converted_text;
93 if (base::CodepageToUTF16(text, encoding_name, 93 if (base::CodepageToUTF16(text, encoding_name,
94 base::OnStringConversionError::FAIL, 94 base::OnStringConversionError::SUBSTITUTE,
95 &converted_text)) { 95 &converted_text)) {
96 const char* const kNewlineSeparators[] = {"\n", "\r\n"}; 96 const char* const kNewlineSeparators[] = {"\n", "\r\n"};
97 97
98 for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) { 98 for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) {
99 int rv = ParseListing(converted_text, 99 int rv = ParseListing(converted_text,
100 base::ASCIIToUTF16(kNewlineSeparators[j]), 100 base::ASCIIToUTF16(kNewlineSeparators[j]),
101 encoding_name, current_time, entries, server_type); 101 encoding_name, current_time, entries, server_type);
102 if (rv == OK) 102 if (rv == OK)
103 return rv; 103 return rv;
104 } 104 }
(...skipping 14 matching lines...) Expand all
119 int ParseFtpDirectoryListing(const std::string& text, 119 int ParseFtpDirectoryListing(const std::string& text,
120 const base::Time& current_time, 120 const base::Time& current_time,
121 std::vector<FtpDirectoryListingEntry>* entries) { 121 std::vector<FtpDirectoryListingEntry>* entries) {
122 FtpServerType server_type = SERVER_UNKNOWN; 122 FtpServerType server_type = SERVER_UNKNOWN;
123 int rv = DecodeAndParse(text, current_time, entries, &server_type); 123 int rv = DecodeAndParse(text, current_time, entries, &server_type);
124 UpdateFtpServerTypeHistograms(server_type); 124 UpdateFtpServerTypeHistograms(server_type);
125 return rv; 125 return rv;
126 } 126 }
127 127
128 } // namespace net 128 } // namespace net
OLDNEW
« no previous file with comments | « net/data/ftp/dir-listing-ls-34.expected ('k') | net/ftp/ftp_directory_listing_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698