comphelper/source/misc/DirectoryHelper.cxx | 11 +++++++++-- include/comphelper/DirectoryHelper.hxx | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-)
New commits: commit 3eb58057b0a936ba76d1a5a587f9bda2dccfe862 Author: Jan-Marek Glogowski <glo...@fbihome.de> AuthorDate: Sat Sep 18 02:08:24 2021 +0200 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Sat Sep 18 17:17:43 2021 +0200 URI-encode DirectoryHelper::scanDirsAndFiles result All code assumes the result is usable as URI segments. This fails DirectoryHelper::deleteDirRecursively with files like org.openoffice.da.hunspell.dictionaries%2Fpage1.xhp, resulting in an unlimited startup loop after creating a new user profile via: $ soffice -env:UserInstallation=file:///tmp/test --safe-mode $ soffice -env:UserInstallation=file:///tmp/test So just URI encode all files and directories returned. This doesn't fix the general problem handling "regular" DirectoryHelper::deleteDirRecursively failures on startup. Change-Id: I48aa9816118e19302eb93387bdd741bf27fa7236 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122292 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/comphelper/source/misc/DirectoryHelper.cxx b/comphelper/source/misc/DirectoryHelper.cxx index 4ac2dfe7e829..f444d9450664 100644 --- a/comphelper/source/misc/DirectoryHelper.cxx +++ b/comphelper/source/misc/DirectoryHelper.cxx @@ -11,6 +11,7 @@ #include <sal/config.h> #include <osl/file.hxx> +#include <rtl/uri.hxx> #include <memory> @@ -77,6 +78,11 @@ void DirectoryHelper::scanDirsAndFiles(const OUString& rDirURL, std::set<OUStrin if (osl::FileBase::E_None != aDirectory.open()) return; + auto lcl_encodeUriSegment = [](OUString const& rPath) { + return rtl::Uri::encode(rPath, rtl_UriCharClassUricNoSlash, rtl_UriEncodeIgnoreEscapes, + RTL_TEXTENCODING_UTF8); + }; + osl::DirectoryItem aDirectoryItem; while (osl::FileBase::E_None == aDirectory.getNextItem(aDirectoryItem)) @@ -92,7 +98,7 @@ void DirectoryHelper::scanDirsAndFiles(const OUString& rDirURL, std::set<OUStrin if (!aFileName.isEmpty()) { - rDirs.insert(aFileName); + rDirs.insert(lcl_encodeUriSegment(aFileName)); } } else if (aFileStatus.isRegular()) @@ -103,7 +109,8 @@ void DirectoryHelper::scanDirsAndFiles(const OUString& rDirURL, std::set<OUStrin if (!aFileName.isEmpty()) { - rFiles.insert(std::pair<OUString, OUString>(aFileName, aExtension)); + rFiles.insert(std::pair<OUString, OUString>(lcl_encodeUriSegment(aFileName), + lcl_encodeUriSegment(aExtension))); } } } diff --git a/include/comphelper/DirectoryHelper.hxx b/include/comphelper/DirectoryHelper.hxx index e614252beaf4..56c017da476d 100644 --- a/include/comphelper/DirectoryHelper.hxx +++ b/include/comphelper/DirectoryHelper.hxx @@ -24,6 +24,8 @@ public: static OUString splitAtLastToken(const OUString& rSrc, sal_Unicode aToken, OUString& rRight); static bool fileExists(const OUString& rBaseURL); static bool dirExists(const OUString& rDirURL); + + // all rDirs and rFiles strings are already URI encoded, so safe for concat static void scanDirsAndFiles(const OUString& rDirURL, std::set<OUString>& rDirs, std::set<std::pair<OUString, OUString>>& rFiles); static bool deleteDirRecursively(const OUString& rDirURL);