diff options
author | joaoe@opera.com <joaoe@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-09 12:20:40 +0000 |
---|---|---|
committer | joaoe@opera.com <joaoe@opera.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-09 12:20:40 +0000 |
commit | ad4fc2d7d4b6c6415aaa2ef422c8f896544a02fa (patch) | |
tree | 808096e553052f2db4c5bbc6975a2f1987cc8282 /third_party/zlib | |
parent | c15257986c5c57352de8877230cc2cd6b5fbb02b (diff) | |
download | chromium_src-ad4fc2d7d4b6c6415aaa2ef422c8f896544a02fa.zip chromium_src-ad4fc2d7d4b6c6415aaa2ef422c8f896544a02fa.tar.gz chromium_src-ad4fc2d7d4b6c6415aaa2ef422c8f896544a02fa.tar.bz2 |
Followup for bug when zipping a folder with non-ascii chars in its name.
The commit adds a unit test and replaces the substr with the more
stylistically adequate FilePath::AppendRelativePath.
BUG=248115
TEST=ZipTest.ZipNonASCIIDir
Review URL: https://codereview.chromium.org/106663006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/zlib')
-rw-r--r-- | third_party/zlib/google/zip.cc | 6 | ||||
-rw-r--r-- | third_party/zlib/google/zip_unittest.cc | 18 |
2 files changed, 22 insertions, 2 deletions
diff --git a/third_party/zlib/google/zip.cc b/third_party/zlib/google/zip.cc index a7bcc3c..d1ba74f 100644 --- a/third_party/zlib/google/zip.cc +++ b/third_party/zlib/google/zip.cc @@ -51,8 +51,10 @@ bool AddFileToZip(zipFile zip_file, const base::FilePath& src_dir) { bool AddEntryToZip(zipFile zip_file, const base::FilePath& path, const base::FilePath& root_path) { - std::string str_path = - path.AsUTF8Unsafe().substr(root_path.AsUTF8Unsafe().length() + 1); + base::FilePath relative_path; + bool result = root_path.AppendRelativePath(path, &relative_path); + DCHECK(result); + std::string str_path = relative_path.AsUTF8Unsafe(); #if defined(OS_WIN) ReplaceSubstringsAfterOffset(&str_path, 0u, "\\", "/"); #endif diff --git a/third_party/zlib/google/zip_unittest.cc b/third_party/zlib/google/zip_unittest.cc index 0572b85..1023705 100644 --- a/third_party/zlib/google/zip_unittest.cc +++ b/third_party/zlib/google/zip_unittest.cc @@ -174,6 +174,24 @@ TEST_F(ZipTest, ZipIgnoreHidden) { TestUnzipFile(zip_file, false); } +TEST_F(ZipTest, ZipNonASCIIDir) { + base::FilePath src_dir; + ASSERT_TRUE(GetTestDataDirectory(&src_dir)); + src_dir = src_dir.AppendASCII("test"); + + base::ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + // Append 'Тест' (in cyrillic). + base::FilePath src_dir_russian = + temp_dir.path().Append(base::FilePath::FromUTF8Unsafe( + "\xD0\xA2\xD0\xB5\xD1\x81\xD1\x82")); + base::CopyDirectory(src_dir, src_dir_russian, true); + base::FilePath zip_file = temp_dir.path().AppendASCII("out_russian.zip"); + + EXPECT_TRUE(zip::Zip(src_dir_russian, zip_file, true)); + TestUnzipFile(zip_file, true); +} + #if defined(OS_POSIX) TEST_F(ZipTest, ZipFiles) { base::FilePath src_dir; |