From: Vadim Zeitlin Date: Sun, 7 Jan 2007 16:36:54 +0000 (+0000) Subject: fix wxConfig::DeleteGroup() for arguments with trailing slash (replaces patch 1624589) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/35c4b4da0a28029dc841147ef6fd183b87d2cc8f fix wxConfig::DeleteGroup() for arguments with trailing slash (replaces patch 1624589) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 320d536fc6..27060de0e4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -97,6 +97,7 @@ All: - wxGrid::GetBestSize() returns same size the grid would have after AutoSize() - Added wxTreeCtrl::CollapseAll[Children]() and IsEmpty() (Francesco Montorsi) - Several RTL-related positioning fixes (Diaa Sami) +- Fix wxConfig::DeleteGroup() for arguments with trailing slash (David Hart) wxMSW: diff --git a/include/wx/confbase.h b/include/wx/confbase.h index 63b755f0f9..1d58ac75a6 100644 --- a/include/wx/confbase.h +++ b/include/wx/confbase.h @@ -225,7 +225,7 @@ public: // delete the group (with all subgroups) virtual bool DeleteGroup(const wxString& key) = 0; // delete the whole underlying object (disk file, registry key, ...) - // primarly for use by desinstallation routine. + // primarily for use by uninstallation routine. virtual bool DeleteAll() = 0; // options @@ -254,6 +254,13 @@ protected: static bool IsImmutable(const wxString& key) { return !key.IsEmpty() && key[0] == wxCONFIG_IMMUTABLE_PREFIX; } + // return the path without trailing separator, if any: this should be called + // to sanitize paths referring to the group names before passing them to + // wxConfigPathChanger as "/foo/bar/" should be the same as "/foo/bar" and it + // isn't interpreted in the same way by it (and this can't be changed there + // as it's not the same for the entries names) + static wxString RemoveTrailingSeparator(const wxString& key); + // do read/write the values of different types virtual bool DoReadString(const wxString& key, wxString *pStr) const = 0; virtual bool DoReadLong(const wxString& key, long *pl) const = 0; diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 8d67e3a4f7..b47cb982a5 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -1172,7 +1172,7 @@ bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso) bool wxFileConfig::DeleteGroup(const wxString& key) { - wxConfigPathChanger path(this, key); + wxConfigPathChanger path(this, RemoveTrailingSeparator(key)); if ( !m_pCurrentGroup->DeleteSubgroupByName(path.Name()) ) return false; diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 1777569b88..71b62aeb95 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -697,7 +697,7 @@ bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso) bool wxRegConfig::DeleteGroup(const wxString& key) { - wxConfigPathChanger path(this, key); + wxConfigPathChanger path(this, RemoveTrailingSeparator(key)); if ( !m_keyLocal.Exists() ) { diff --git a/tests/fileconf/fileconftest.cpp b/tests/fileconf/fileconftest.cpp index 7c90ff4612..fa10884e15 100644 --- a/tests/fileconf/fileconftest.cpp +++ b/tests/fileconf/fileconftest.cpp @@ -309,7 +309,8 @@ void FileConfigTestCase::DeleteGroup() _T("[root/group2]\n"), fc ); - CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2")) ); + // notice trailing slash: it should be ignored + CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2/")) ); wxVERIFY_FILECONFIG( _T("[root]\n") _T("entry=value\n"), fc );