From 3bd1b85cdc00456e35d286d3d76ffd7b36c5e03e Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 25 Nov 2019 10:00:29 +0000 Subject: don't just truncate the unicode chars of the path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead convert to a systempath like we do for other uses of xmlParseFile drop the manual memory management Change-Id: I8c3329db4b47a2d212770297c96f066ccbe1ec77 Reviewed-on: https://gerrit.libreoffice.org/83692 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- .../customize/CustomNotebookbarGenerator.cxx | 57 ++++++++++------------ cui/source/customize/SvxNotebookbarConfigPage.cxx | 11 ++--- 2 files changed, 30 insertions(+), 38 deletions(-) (limited to 'cui/source/customize') diff --git a/cui/source/customize/CustomNotebookbarGenerator.cxx b/cui/source/customize/CustomNotebookbarGenerator.cxx index d8e597f90f1e..8c135b96b8ff 100644 --- a/cui/source/customize/CustomNotebookbarGenerator.cxx +++ b/cui/source/customize/CustomNotebookbarGenerator.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -126,13 +127,19 @@ static OUString getUIDirPath() return sUIDirPath; } -char* CustomNotebookbarGenerator::convertToCharPointer(const OUString& sString) +OString CustomNotebookbarGenerator::getSystemPath(OUString const& sURL) { - char* cString = new char[sString.getLength() + 1]; - for (int nIdx = 0; nIdx < sString.getLength(); nIdx++) - *(cString + nIdx) = char(sString[nIdx]); - *(cString + sString.getLength()) = '\0'; - return cString; + if (sURL.isEmpty()) + return OString(); + OUString sSystemPathSettings; + if (osl_getSystemPathFromFileURL(sURL.pData, &sSystemPathSettings.pData) != osl_File_E_None) + { + SAL_WARN("cui.customnotebookbar", "Cannot get system path for :" << sURL); + return OString(); + } + OString osSystemPathSettings + = OUStringToOString(sSystemPathSettings, osl_getThreadTextEncoding()); + return osSystemPathSettings; } static void changeNodeValue(xmlNode* pNodePtr, const char* pProperty, const char* pValue) @@ -173,48 +180,36 @@ static void searchNodeAndAttribute(xmlNode* pNodePtr, const char* pUIItemID, con } } -static xmlDocPtr notebookbarXMLParser(const char* pDocName, char* pUIItemID, char* pProperty, - char* pValue) +static xmlDocPtr notebookbarXMLParser(const OString& rDocName, const OString& rUIItemID, + const OString& rProperty, const OString& rValue) { - xmlDocPtr pDocPtr; - xmlNodePtr pNodePtr; - - pDocPtr = xmlParseFile(pDocName); - pNodePtr = xmlDocGetRootElement(pDocPtr); - searchNodeAndAttribute(pNodePtr, pUIItemID, pProperty, pValue); + xmlDocPtr pDocPtr = xmlParseFile(rDocName.getStr()); + xmlNodePtr pNodePtr = xmlDocGetRootElement(pDocPtr); + searchNodeAndAttribute(pNodePtr, rUIItemID.getStr(), rProperty.getStr(), rValue.getStr()); return pDocPtr; } void CustomNotebookbarGenerator::modifyCustomizedUIFile(const Sequence& sUIItemProperties) { - OUString sCustomizedUIPath = getCustomizedUIPath(); - char* cCustomizedUIPath = convertToCharPointer(sCustomizedUIPath); + OString sCustomizedUIPath = getSystemPath(getCustomizedUIPath()); for (auto const& aValue : sUIItemProperties) { - char** pProperties = new char*[aUIPropertiesCount]; + std::vector aProperties(aUIPropertiesCount); for (sal_Int32 aIndex = 0; aIndex < aUIPropertiesCount; aIndex++) { - int nIdx = int(aIndex); - sal_Int32 rPos = aIndex; - pProperties[nIdx] = convertToCharPointer(aValue.getToken(rPos, ',', rPos)); - } - xmlDocPtr doc; - doc = notebookbarXMLParser(cCustomizedUIPath, pProperties[0], pProperties[1], - pProperties[2]); - - for (int nIdx = 0; nIdx < aUIPropertiesCount; nIdx++) - { - delete[] pProperties[nIdx]; + sal_Int32 nPos = aIndex; + OUString sToken = aValue.getToken(nPos, ',', nPos); + aProperties[aIndex] = OUStringToOString(sToken, RTL_TEXTENCODING_UTF8); } - delete[] pProperties; + xmlDocPtr doc = notebookbarXMLParser(sCustomizedUIPath, aProperties[0], aProperties[1], + aProperties[2]); if (doc != nullptr) { - xmlSaveFormatFile(cCustomizedUIPath, doc, 1); + xmlSaveFormatFile(sCustomizedUIPath.getStr(), doc, 1); xmlFreeDoc(doc); } } - delete[] cCustomizedUIPath; } void CustomNotebookbarGenerator::getFileNameAndAppName(OUString& sAppName, diff --git a/cui/source/customize/SvxNotebookbarConfigPage.cxx b/cui/source/customize/SvxNotebookbarConfigPage.cxx index af5bed877aef..cd654fa717c8 100644 --- a/cui/source/customize/SvxNotebookbarConfigPage.cxx +++ b/cui/source/customize/SvxNotebookbarConfigPage.cxx @@ -435,12 +435,10 @@ void SvxNotebookbarConfigPage::FillFunctionsList(std::vector std::vector& aCategoryList, OUString& sActiveCategory) { - xmlDocPtr pDoc; - xmlNodePtr pNodePtr; - OUString sUIFilePath = CustomNotebookbarGenerator::getCustomizedUIPath(); - char* cUIFileUIPath = CustomNotebookbarGenerator::convertToCharPointer(sUIFilePath); - pDoc = xmlParseFile(cUIFileUIPath); - pNodePtr = xmlDocGetRootElement(pDoc); + OString sUIFileUIPath = CustomNotebookbarGenerator::getSystemPath( + CustomNotebookbarGenerator::getCustomizedUIPath()); + xmlDocPtr pDoc = xmlParseFile(sUIFileUIPath.getStr()); + xmlNodePtr pNodePtr = xmlDocGetRootElement(pDoc); CategoriesEntries aCurItemEntry; searchNodeandAttribute(aEntries, aCategoryList, sActiveCategory, aCurItemEntry, pNodePtr, @@ -449,7 +447,6 @@ void SvxNotebookbarConfigPage::FillFunctionsList(std::vector { xmlFreeDoc(pDoc); } - delete[] cUIFileUIPath; } void SvxNotebookbarConfigPage::SelectElement() -- cgit