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

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

Issue 2608213002: Make FTP directory parser less strict (Closed)
Patch Set: add a test 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 73 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::SKIP,
mmenke 2017/01/05 00:20:53 Would SUBSTITUTE be better, so we display a charac
Jinsuk Kim 2017/01/05 00:25:39 Tried this but then the processing in |ParseListin
Jinsuk Kim 2017/01/05 00:45:28 Your feedback got me to look into it further... SU
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