diff --git a/src/vmime/utility/path.cpp b/src/vmime/utility/path.cpp index 9f746d54..59685866 100644 --- a/src/vmime/utility/path.cpp +++ b/src/vmime/utility/path.cpp @@ -134,8 +134,7 @@ bool path::operator==(const path& p) const bool equal = true; for ( ; equal && i != m_list.end() ; ++i, ++j) - //equal = (*i == *j); - equal = ((*i).getBuffer() == (*j).getBuffer()); + equal = ((*i).isEquivalent(*j)); return (equal); } @@ -197,7 +196,7 @@ bool path::isDirectParentOf(const path& p) const bool equal = true; for (list::size_type i = 0 ; equal && i < m_list.size() ; ++i) - equal = (m_list[i] == p.m_list[i]); + equal = (m_list[i].isEquivalent(p.m_list[i])); return (equal); } @@ -211,7 +210,7 @@ bool path::isParentOf(const path& p) const bool equal = true; for (list::size_type i = 0 ; equal && i < m_list.size() ; ++i) - equal = (m_list[i] == p.m_list[i]); + equal = (m_list[i].isEquivalent(p.m_list[i])); return (equal); } @@ -226,7 +225,7 @@ void path::renameParent(const path& oldPath, const path& newPath) list::size_type i; for (i = 0 ; equal && i < oldPath.m_list.size() ; ++i) - equal = (m_list[i] == oldPath.m_list[i]); + equal = (m_list[i].isEquivalent(oldPath.m_list[i])); if (i != oldPath.m_list.size()) return; diff --git a/src/vmime/word.cpp b/src/vmime/word.cpp index 2ee4d3e7..4b99fbc3 100644 --- a/src/vmime/word.cpp +++ b/src/vmime/word.cpp @@ -723,6 +723,12 @@ bool word::operator!=(const word& w) const } +bool word::isEquivalent(const word& other) const +{ + return getConvertedText(charset(charsets::UTF_8)) == other.getConvertedText(charset(charsets::UTF_8)); +} + + const string word::getConvertedText(const charset& dest, const charsetConverterOptions& opts) const { string out; diff --git a/src/vmime/word.hpp b/src/vmime/word.hpp index a6e2402e..4122228d 100644 --- a/src/vmime/word.hpp +++ b/src/vmime/word.hpp @@ -85,6 +85,14 @@ public: */ void setCharset(const charset& ch); + /** Returns whether two words actually represent the same text, + * regardless of their charset. + * + * @param other word to compare to + * @return true if the two words represent the same text, or false otherwise + */ + bool isEquivalent(const word& other) const; + word& operator=(const word& w); word& operator=(const string& s); diff --git a/tests/utility/pathTest.cpp b/tests/utility/pathTest.cpp index 93215586..d0c1c091 100644 --- a/tests/utility/pathTest.cpp +++ b/tests/utility/pathTest.cpp @@ -26,7 +26,7 @@ #include "vmime/utility/path.hpp" -VMIME_TEST_SUITE_BEGIN(pathTest) +VMIME_TEST_SUITE_BEGIN(utilityPathTest) VMIME_TEST_LIST_BEGIN VMIME_TEST(testConstruct1) @@ -50,6 +50,7 @@ VMIME_TEST_SUITE_BEGIN(pathTest) VMIME_TEST(testIsDirectParentOf) VMIME_TEST(testIsParentOf) + VMIME_TEST(testIsParentOf_EquivalentCharset) VMIME_TEST(testRenameParent) VMIME_TEST_LIST_END @@ -271,6 +272,19 @@ VMIME_TEST_SUITE_BEGIN(pathTest) VASSERT_EQ("4", false, p2.isParentOf(p1)); } + void testIsParentOf_EquivalentCharset() + { + path p1; + p1.appendComponent(comp("foo", "us-ascii")); + + path p2; + p2.appendComponent(comp("foo", "utf-8")); + p2.appendComponent(comp("bar")); + p2.appendComponent(comp("baz")); + + VASSERT_EQ("1", true, p1.isParentOf(p2)); + } + void testRenameParent() { path p1;