diff options
-rw-r--r-- | sfx2/CppunitTest_sfx2_doc.mk | 1 | ||||
-rw-r--r-- | sfx2/qa/cppunit/doc.cxx | 31 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 17 |
3 files changed, 39 insertions, 10 deletions
diff --git a/sfx2/CppunitTest_sfx2_doc.mk b/sfx2/CppunitTest_sfx2_doc.mk index 02b06dfd1b14..bf181c2325d6 100644 --- a/sfx2/CppunitTest_sfx2_doc.mk +++ b/sfx2/CppunitTest_sfx2_doc.mk @@ -27,6 +27,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_doc, \ unotest \ sfx \ svl \ + utl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,sfx2_doc)) diff --git a/sfx2/qa/cppunit/doc.cxx b/sfx2/qa/cppunit/doc.cxx index 01e8fd7f2000..058bf4788d67 100644 --- a/sfx2/qa/cppunit/doc.cxx +++ b/sfx2/qa/cppunit/doc.cxx @@ -17,6 +17,9 @@ #include <comphelper/propertyvalue.hxx> #include <sfx2/objsh.hxx> #include <sfx2/sfxbasemodel.hxx> +#include <unotools/tempfile.hxx> +#include <sfx2/docfile.hxx> +#include <osl/file.hxx> using namespace com::sun::star; @@ -74,6 +77,34 @@ CPPUNIT_TEST_FIXTURE(Test, testNoGrabBagShape) // which was not caught later, resulting in a crash. pObjectShell->GetSignPDFCertificate(); } + +CPPUNIT_TEST_FIXTURE(Test, testTempFilePath) +{ + // Create a test file in a directory that contains the URL-encoded "testÿ" string. + getComponent() = loadFromDesktop("private:factory/swriter"); + auto pBaseModel = dynamic_cast<SfxBaseModel*>(getComponent().get()); + CPPUNIT_ASSERT(pBaseModel); + OUString aTargetDir + = m_directories.getURLFromWorkdir(u"CppunitTest/sfx2_doc.test.user/test%25C3%25Bf"); + osl::Directory::create(aTargetDir); + OUString aTargetFile = aTargetDir + "/test.odt"; + css::uno::Sequence<css::beans::PropertyValue> aArgs{ comphelper::makePropertyValue( + "FilterName", OUString("writer8")) }; + pBaseModel->storeAsURL(aTargetFile, aArgs); + getComponent()->dispose(); + + // Load it and export to PDF. + getComponent() = loadFromDesktop(aTargetFile); + pBaseModel = dynamic_cast<SfxBaseModel*>(getComponent().get()); + OUString aPdfTarget = aTargetDir + "/test.pdf"; + css::uno::Sequence<css::beans::PropertyValue> aPdfArgs{ comphelper::makePropertyValue( + "FilterName", OUString("writer_pdf_Export")) }; + // Without the accompanying fix in place, this test would have failed on Windows with: + // An uncaught exception of type com.sun.star.io.IOException + // because we first tried to create a temp file next to test.odt in a directory named + // "test%25C3%25Bf" instead of a directory named "test%C3%Bf". + pBaseModel->storeToURL(aPdfTarget, aPdfArgs); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 7a1bf5a7f2c9..59865fb2b8eb 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -3620,7 +3620,7 @@ bool SfxMedium::SetWritableForUserOnly( const OUString& aURL ) namespace { /// Get the parent directory of a temporary file for output purposes. -OUString GetLogicBase(std::unique_ptr<SfxMedium_Impl> const & pImpl) +OUString GetLogicBase(const INetURLObject& rURL, std::unique_ptr<SfxMedium_Impl> const & pImpl) { OUString aLogicBase; @@ -3631,15 +3631,12 @@ OUString GetLogicBase(std::unique_ptr<SfxMedium_Impl> const & pImpl) (void) pImpl; #else - if (comphelper::isFileUrl(pImpl->m_aLogicName) && !pImpl->m_pInStream) + if (rURL.GetProtocol() == INetProtocol::File && !pImpl->m_pInStream) { // Try to create the temp file in the same directory when storing. - sal_Int32 nOffset = pImpl->m_aLogicName.lastIndexOf("/"); - if (nOffset != -1) - aLogicBase = pImpl->m_aLogicName.copy(0, nOffset); - if (aLogicBase == "file://") - // Doesn't make sense. - aLogicBase.clear(); + INetURLObject aURL(rURL); + aURL.removeSegment(); + aLogicBase = aURL.GetMainURL(INetURLObject::DecodeMechanism::WithCharset); } if (pImpl->m_bHasEmbeddedObjects) @@ -3663,7 +3660,7 @@ void SfxMedium::CreateTempFile( bool bReplace ) pImpl->m_aName.clear(); } - OUString aLogicBase = GetLogicBase(pImpl); + OUString aLogicBase = GetLogicBase(GetURLObject(), pImpl); pImpl->pTempFile.reset( new ::utl::TempFile(aLogicBase.isEmpty() ? nullptr : &aLogicBase) ); pImpl->pTempFile->EnableKillingFile(); pImpl->m_aName = pImpl->pTempFile->GetFileName(); @@ -3759,7 +3756,7 @@ void SfxMedium::CreateTempFileNoCopy() // this call always replaces the existing temporary file pImpl->pTempFile.reset(); - OUString aLogicBase = GetLogicBase(pImpl); + OUString aLogicBase = GetLogicBase(GetURLObject(), pImpl); pImpl->pTempFile.reset( new ::utl::TempFile(aLogicBase.isEmpty() ? nullptr : &aLogicBase) ); pImpl->pTempFile->EnableKillingFile(); pImpl->m_aName = pImpl->pTempFile->GetFileName(); |