[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Jul 6 12:07:16 UTC 2018
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 46683a7130ff3c2a6377a0af810b633ad964c52f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
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.
Reviewed-on: https://gerrit.libreoffice.org/56989
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins
(cherry picked from commit bcc9feb94c481ee885c763d8fadfc9209acb117c)
Conflicts:
sw/source/filter/html/swhtml.hxx
Change-Id: Icb7991082b6e595db5729f3c4c84073c80834f27
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 79d5da7875a2..a9ed8dde14c4 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 122f639dd4f6..c71cb4e5a951 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -340,7 +340,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 05c9495fd59d..70456390f54c 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;
@@ -300,6 +301,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;
@@ -423,9 +437,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 27dfd2965360..c20e791f62b8 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -904,6 +904,9 @@ public:
virtual bool ParseMetaOptions( const css::uno::Reference<css::document::XDocumentProperties>&,
SvKeyValueIterator* ) override;
+
+ /// 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
More information about the Libreoffice-commits
mailing list