summaryrefslogtreecommitdiffstats
path: root/net/ftp
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-11 09:19:30 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-11 09:19:30 +0000
commit193c35145799c33bde24a470f460587954d70aba (patch)
tree330c97462719bb266940cec9cd40ea70531d8500 /net/ftp
parent587f4ff6420df90d4e6160aeb78918fcf55e3599 (diff)
downloadchromium_src-193c35145799c33bde24a470f460587954d70aba.zip
chromium_src-193c35145799c33bde24a470f460587954d70aba.tar.gz
chromium_src-193c35145799c33bde24a470f460587954d70aba.tar.bz2
FTP: fix navigating to files listed under non-ASCII characters
We need to convert the file name back to server encoding. BUG=38016 TEST=see bug Review URL: http://codereview.chromium.org/1857002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46900 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r--net/ftp/ftp_directory_listing_buffer.cc34
-rw-r--r--net/ftp/ftp_directory_listing_buffer.h2
2 files changed, 7 insertions, 29 deletions
diff --git a/net/ftp/ftp_directory_listing_buffer.cc b/net/ftp/ftp_directory_listing_buffer.cc
index bc2db9c..41daeb4 100644
--- a/net/ftp/ftp_directory_listing_buffer.cc
+++ b/net/ftp/ftp_directory_listing_buffer.cc
@@ -4,6 +4,7 @@
#include "net/ftp/ftp_directory_listing_buffer.h"
+#include "base/i18n/icu_encoding_detection.h"
#include "base/i18n/icu_string_conversions.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
@@ -13,33 +14,6 @@
#include "net/ftp/ftp_directory_listing_parser_netware.h"
#include "net/ftp/ftp_directory_listing_parser_vms.h"
#include "net/ftp/ftp_directory_listing_parser_windows.h"
-#include "unicode/ucsdet.h"
-
-namespace {
-
-// A very simple-minded character encoding detection.
-// TODO(jungshik): We can apply more heuristics here (e.g. using various hints
-// like TLD, the UI language/default encoding of a client, etc). In that case,
-// this should be pulled out of here and moved somewhere in base because there
-// can be other use cases.
-std::string DetectEncoding(const std::string& text) {
- if (IsStringASCII(text))
- return std::string();
- UErrorCode status = U_ZERO_ERROR;
- UCharsetDetector* detector = ucsdet_open(&status);
- ucsdet_setText(detector, text.data(), static_cast<int32_t>(text.length()),
- &status);
- const UCharsetMatch* match = ucsdet_detect(detector, &status);
- const char* encoding = ucsdet_getName(match, &status);
- ucsdet_close(detector);
- // Should we check the quality of the match? A rather arbitrary number is
- // assigned by ICU and it's hard to come up with a lower limit.
- if (U_FAILURE(status))
- return std::string();
- return encoding;
-}
-
-} // namespace
namespace net {
@@ -109,8 +83,10 @@ bool FtpDirectoryListingBuffer::ConvertToDetectedEncoding(
}
int FtpDirectoryListingBuffer::ExtractFullLinesFromBuffer() {
- if (encoding_.empty())
- encoding_ = DetectEncoding(buffer_);
+ if (encoding_.empty()) {
+ if (!base::DetectEncoding(buffer_, &encoding_))
+ return ERR_ENCODING_DETECTION_FAILED;
+ }
int cut_pos = 0;
// TODO(phajdan.jr): This code accepts all endlines matching \r*\n. Should it
diff --git a/net/ftp/ftp_directory_listing_buffer.h b/net/ftp/ftp_directory_listing_buffer.h
index 7aead49..4123cf0 100644
--- a/net/ftp/ftp_directory_listing_buffer.h
+++ b/net/ftp/ftp_directory_listing_buffer.h
@@ -45,6 +45,8 @@ class FtpDirectoryListingBuffer {
// time, although it will return SERVER_UNKNOWN if it doesn't know the answer.
FtpServerType GetServerType() const;
+ const std::string& encoding() const { return encoding_; }
+
private:
typedef std::set<FtpDirectoryListingParser*> ParserSet;