sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml | 2 +- sw/qa/extras/htmlexport/data/reqif-png-img.xhtml | 2 +- sw/qa/extras/htmlexport/htmlexport.cxx | 3 +++ sw/source/filter/html/htmlgrin.cxx | 3 ++- sw/source/filter/html/htmlplug.cxx | 20 +++++++++++++++++++- sw/source/filter/html/swhtml.hxx | 3 +++ 6 files changed, 29 insertions(+), 4 deletions(-)
New commits: commit bcc9feb94c481ee885c763d8fadfc9209acb117c Author: Miklos Vajna <[email protected]> Date: Thu Jul 5 09:17:18 2018 +0200 sw HTML import: strip query & fragment for <object data="..."> and file URLs There are two cases: when the <object> is a child of an outer <object> (we create an embedded object) and the non-embedded <object> case (we create an image). Call the new SwHTMLParser::StripQueryFromPath() in both cases. INetURLObject considers this query/fragment part as "name" (end of "path"), so just do it manually. Change-Id: Icb7991082b6e595db5729f3c4c84073c80834f27 Reviewed-on: https://gerrit.libreoffice.org/56989 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml b/sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml index b552783068ae..6217412ae597 100644 --- a/sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml +++ b/sw/qa/extras/htmlexport/data/reqif-ole-img.xhtml @@ -1,6 +1,6 @@ <reqif-xhtml:div><reqif-xhtml:br/> <reqif-xhtml:object data="reqif-ole-data.ole" type="text/rtf"> - <reqif-xhtml:object data="reqif-ole-img.png" type="image/png">OLE Object</reqif-xhtml:object> + <reqif-xhtml:object data="reqif-ole-img.png?test=true" type="image/png">OLE Object</reqif-xhtml:object> </reqif-xhtml:object> </reqif-xhtml:div> diff --git a/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml b/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml index f31795e35224..637a7c2ac4b6 100644 --- a/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml +++ b/sw/qa/extras/htmlexport/data/reqif-png-img.xhtml @@ -1,4 +1,4 @@ <reqif-xhtml:div><reqif-xhtml:br/> - <reqif-xhtml:object data="reqif-ole-img.png" type="image/png">OLE Object</reqif-xhtml:object> + <reqif-xhtml:object data="reqif-ole-img.png?test=true" type="image/png">OLE Object</reqif-xhtml:object> </reqif-xhtml:div> diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 8cb60396691d..5d82b82c9524 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -391,6 +391,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml") // This failed, OLE object had no replacement image. // And then it also failed when the export lost the replacement image. uno::Reference<graphic::XGraphic> xGraphic = xObject->getReplacementGraphic(); + // This failed when query and fragment of file:// URLs were not ignored. CPPUNIT_ASSERT(xGraphic.is()); uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY); @@ -456,6 +457,8 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml") // Make sure that both RTF and PNG versions are written. CPPUNIT_ASSERT(aStream.indexOf("text/rtf") != -1); + // This failed when images with a query in their file:// URL failed to + // import. CPPUNIT_ASSERT(aStream.indexOf("image/png") != -1); } diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 0a9050f3475a..8b3ddaf0f601 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -349,7 +349,8 @@ void SwHTMLParser::InsertImage() case HtmlOptionId::DATA: aGraphicData = rOption.GetString(); if (!InternalImgToPrivateURL(aGraphicData)) - aGraphicData = INetURLObject::GetAbsURL(m_sBaseURL, aGraphicData); + aGraphicData = INetURLObject::GetAbsURL( + m_sBaseURL, SwHTMLParser::StripQueryFromPath(m_sBaseURL, aGraphicData)); break; case HtmlOptionId::ALIGN: eVertOri = diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 30277b8bf3a9..22738a13b934 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -72,6 +72,7 @@ #include <unotools/ucbstreamhelper.hxx> #include <comphelper/propertysequence.hxx> #include <filter/msfilter/msoleexp.hxx> +#include <comphelper/fileurl.hxx> using namespace com::sun::star; @@ -299,6 +300,19 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace, } } +OUString SwHTMLParser::StripQueryFromPath(const OUString& rBase, const OUString& rPath) +{ + if (!comphelper::isFileUrl(rBase)) + return rPath; + + sal_Int32 nIndex = rPath.indexOf('?'); + + if (nIndex != -1) + return rPath.copy(0, nIndex); + + return rPath; +} + bool SwHTMLParser::InsertEmbed() { OUString aURL, aType, aName, aAlt, aId, aStyle, aClass; @@ -420,9 +434,13 @@ bool SwHTMLParser::InsertEmbed() INetURLObject(m_sBaseURL), aURL, URIHelper::GetMaybeFileHdl()) ); bool bHasData = !aData.isEmpty(); + try { - aURLObj.SetURL(rtl::Uri::convertRelToAbs(m_sBaseURL, aData)); + // Strip query and everything after that for file:// URLs, browsers do + // the same. + aURLObj.SetURL(rtl::Uri::convertRelToAbs( + m_sBaseURL, SwHTMLParser::StripQueryFromPath(m_sBaseURL, aData))); } catch (const rtl::MalformedUriException& /*rException*/) { diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index d649f4a123e2..ae6a91ad3250 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -963,6 +963,9 @@ public: } void DeregisterHTMLTable(HTMLTable* pOld); + + /// Strips query and fragment from a URL path if base URL is a file:// one. + static OUString StripQueryFromPath(const OUString& rBase, const OUString& rPath); }; struct SwPendingStackData _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
