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

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

Issue 1451993007: Fix FTP dir listing parser to support servers returning a "total n" line with an incorrect negative… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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) 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/ftp/ftp_directory_listing_parser_ls.h" 5 #include "net/ftp/ftp_directory_listing_parser_ls.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 135 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
136 136
137 // Some FTP servers put a "total n" line at the beginning of the listing 137 // Some FTP servers put a "total n" line at the beginning of the listing
138 // (n is an integer). Allow such a line, but only once, and only if it's 138 // (n is an integer). Allow such a line, but only once, and only if it's
139 // the first non-empty line. Do not match the word exactly, because it may 139 // the first non-empty line. Do not match the word exactly, because it may
140 // be in different languages (at least English and German have been seen 140 // be in different languages (at least English and German have been seen
141 // in the field). 141 // in the field).
142 if (columns.size() == 2 && !received_total_line) { 142 if (columns.size() == 2 && !received_total_line) {
143 received_total_line = true; 143 received_total_line = true;
144 144
145 // Some FTP servers incorrectly return a negative integer for "n". Since
146 // this value is ignored anyway, just check any valid integer was
147 // provided.
145 int64 total_number; 148 int64 total_number;
146 if (!base::StringToInt64(columns[1], &total_number)) 149 if (!base::StringToInt64(columns[1], &total_number))
147 return false; 150 return false;
148 if (total_number < 0)
149 return false;
150 151
151 continue; 152 continue;
152 } 153 }
153 154
154 FtpDirectoryListingEntry entry; 155 FtpDirectoryListingEntry entry;
155 156
156 size_t column_offset; 157 size_t column_offset;
157 base::string16 size; 158 base::string16 size;
158 if (!DetectColumnOffsetSizeAndModificationTime(columns, 159 if (!DetectColumnOffsetSizeAndModificationTime(columns,
159 current_time, 160 current_time,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 entry.name = entry.name.substr(0, pos); 222 entry.name = entry.name.substr(0, pos);
222 } 223 }
223 224
224 entries->push_back(entry); 225 entries->push_back(entry);
225 } 226 }
226 227
227 return true; 228 return true;
228 } 229 }
229 230
230 } // namespace net 231 } // namespace net
OLDNEW
« no previous file with comments | « net/data/ftp/dir-listing-ls-33.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