diff options
author | aedla@chromium.org <aedla@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-28 13:47:55 +0000 |
---|---|---|
committer | aedla@chromium.org <aedla@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-28 13:47:55 +0000 |
commit | aeae59f4a1f15e80b6a726734ca6190cf111eeee (patch) | |
tree | 1eddadd678a01096f582865fe9b003fdcbab5727 /base/file_path_unittest.cc | |
parent | de6912ddcad4b29b13a5592d331ebe29cd728924 (diff) | |
download | chromium_src-aeae59f4a1f15e80b6a726734ca6190cf111eeee.zip chromium_src-aeae59f4a1f15e80b6a726734ca6190cf111eeee.tar.gz chromium_src-aeae59f4a1f15e80b6a726734ca6190cf111eeee.tar.bz2 |
Don't allow '\0' characters in FilePath.
BUG=169777
Review URL: https://chromiumcodereview.appspot.com/11642041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path_unittest.cc')
-rw-r--r-- | base/file_path_unittest.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc index ab25543..5a9e5cd 100644 --- a/base/file_path_unittest.cc +++ b/base/file_path_unittest.cc @@ -12,6 +12,9 @@ // This macro helps avoid wrapped lines in the test structs. #define FPL(x) FILE_PATH_LITERAL(x) +// This macro constructs strings which can contain NULs. +#define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1) + struct UnaryTestData { const FilePath::CharType* input; const FilePath::CharType* expected; @@ -1115,6 +1118,40 @@ TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) { } } +TEST_F(FilePathTest, ConstructWithNUL) { + // Assert FPS() works. + ASSERT_TRUE(FPS("a\0b").length() == 3); + + // Test constructor strips '\0' + FilePath path(FPS("a\0b")); + EXPECT_TRUE(path.value().length() == 1); + EXPECT_EQ(path.value(), FPL("a")); +} + +TEST_F(FilePathTest, AppendWithNUL) { + // Assert FPS() works. + ASSERT_TRUE(FPS("b\0b").length() == 3); + + // Test Append() strips '\0' + FilePath path(FPL("a")); + path = path.Append(FPS("b\0b")); + EXPECT_TRUE(path.value().length() == 3); +#if defined(FILE_PATH_USES_WIN_SEPARATORS) + EXPECT_EQ(path.value(), FPL("a\\b")); +#else + EXPECT_EQ(path.value(), FPL("a/b")); +#endif +} + +TEST_F(FilePathTest, ReferencesParentWithNUL) { + // Assert FPS() works. + ASSERT_TRUE(FPS("..\0").length() == 3); + + // Test ReferencesParent() doesn't break with "..\0" + FilePath path(FPS("..\0")); + EXPECT_TRUE(path.ReferencesParent()); +} + #if defined(FILE_PATH_USES_WIN_SEPARATORS) TEST_F(FilePathTest, NormalizePathSeparators) { const struct UnaryTestData cases[] = { |