summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-04-21 17:00:57 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-04-21 18:28:17 +0200
commit7d42346ba77c9c4df241ea40eaf550993ca18783 (patch)
treef67f358a37c298271dd7c8a488244c331b0346c5 /sw
parentd31d038f4e385e228488fd76f6d463a43a2f6266 (diff)
tdf#90421 RTF export: ignore hyperlinks without an URL
Commit fe444d1f74abe417962be0bcd3340f40f2446b58 (fdo#62536: sw: fix AutoCorrect bold/underline on existing AUTOFMT, 2013-06-20) adds an empty inet format hint on the text node during autocorrection, on export we can safely ignore that to provide well-formed output. Change-Id: Iafae941a13e29dcc7d8b4bade5ce94a486b59638
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/inc/swmodeltestbase.hxx6
-rw-r--r--sw/qa/extras/rtfexport/data/tdf90421.fodt8
-rw-r--r--sw/qa/extras/rtfexport/rtfexport.cxx23
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx74
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.hxx3
5 files changed, 80 insertions, 34 deletions
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 7528ced17835..f0d3428ef984 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -240,6 +240,7 @@ protected:
header();
preTest(filename);
load(mpTestDocumentPath, filename);
+ postLoad(filename);
reload(mpFilter, filename);
postTest(filename);
verify();
@@ -289,6 +290,11 @@ protected:
{
}
+ /// Override this function if some special file-specific setup is needed during export test: after load, but before save.
+ virtual void postLoad(const char* /*pFilename*/)
+ {
+ }
+
/**
* Override this function if some special filename-specific teardown is needed
*/
diff --git a/sw/qa/extras/rtfexport/data/tdf90421.fodt b/sw/qa/extras/rtfexport/data/tdf90421.fodt
new file mode 100644
index 000000000000..a0da4b8274d8
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf90421.fodt
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <text:p text:style-name="P1">A <text:a xlink:type="simple" xlink:href="http://s/" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">http://s/</text:a> B</text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 20f2a7d4c9e4..33d6ca41f6d2 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -78,6 +78,16 @@ public:
return false;
}
+
+ virtual void postLoad(const char* pFilename) SAL_OVERRIDE
+ {
+ if (OString(pFilename) == "tdf90421.fodt")
+ {
+ // Change the hyperlink, so its URL is empty.
+ uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 2), uno::UNO_QUERY);
+ xRun->setPropertyValue("HyperLinkURL", uno::makeAny(OUString()));
+ }
+ }
};
DECLARE_RTFEXPORT_TEST(testZoom, "zoom.rtf")
@@ -889,6 +899,19 @@ DECLARE_RTFEXPORT_TEST(testTdf80708, "tdf80708.rtf")
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators").getLength());
}
+DECLARE_RTFEXPORT_TEST(testTdf90421, "tdf90421.fodt")
+{
+ if (mbExported)
+ {
+ SvMemoryStream aMemoryStream;
+ SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+ aStream.ReadStream(aMemoryStream);
+ OString aData(static_cast<const char*>(aMemoryStream.GetData()), aMemoryStream.GetSize());
+ // This was some positive number, i.e. we exported a hyperlink with an empty URL.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), aData.indexOf("HYPERLINK"));
+ }
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 54ab98449ca0..6290ae0bd061 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -423,52 +423,58 @@ void RtfAttributeOutput::EndRuby()
bool RtfAttributeOutput::StartURL(const OUString& rUrl, const OUString& rTarget)
{
- m_aStyles.append('{');
- m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FIELD);
- m_aStyles.append('{');
- m_aStyles.append(OOO_STRING_SVTOOLS_RTF_IGNORE);
- m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FLDINST);
- m_aStyles.append(" HYPERLINK ");
-
- OUString sURL(rUrl);
- if (!sURL.isEmpty())
+ m_sURL = rUrl;
+ // Ignore hyperlink without an URL.
+ if (!rUrl.isEmpty())
{
+ m_aStyles.append('{');
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FIELD);
+ m_aStyles.append('{');
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_IGNORE);
+ m_aStyles.append(OOO_STRING_SVTOOLS_RTF_FLDINST);
+ m_aStyles.append(" HYPERLINK ");
+
+ OUString sURL(rUrl);
m_aStyles.append("\"");
m_aStyles.append(msfilter::rtfutil::OutString(sURL, m_rExport.eCurrentEncoding));
m_aStyles.append("\" ");
- }
- if (!rTarget.isEmpty())
- {
- m_aStyles.append("\\\\t \"");
- m_aStyles.append(msfilter::rtfutil::OutString(rTarget, m_rExport.eCurrentEncoding));
- m_aStyles.append("\" ");
- }
+ if (!rTarget.isEmpty())
+ {
+ m_aStyles.append("\\\\t \"");
+ m_aStyles.append(msfilter::rtfutil::OutString(rTarget, m_rExport.eCurrentEncoding));
+ m_aStyles.append("\" ");
+ }
- m_aStyles.append("}");
- m_aStyles.append("{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {");
+ m_aStyles.append("}");
+ m_aStyles.append("{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {");
+ }
return true;
}
bool RtfAttributeOutput::EndURL(bool const isAtEndOfParagraph)
{
- // UGLY: usually EndRun is called earlier, but there is an extra
- // call to OutAttrWithRange() when at the end of the paragraph,
- // so in that special case the output needs to be appended to the
- // new run's text instead of the previous run
- if (isAtEndOfParagraph)
+ if (!m_sURL.isEmpty())
{
- // close the fldrslt group
- m_aRunText->append("}}");
- // close the field group
- m_aRunText->append('}');
- }
- else
- {
- // close the fldrslt group
- m_aRun->append("}}");
- // close the field group
- m_aRun->append('}');
+ // UGLY: usually EndRun is called earlier, but there is an extra
+ // call to OutAttrWithRange() when at the end of the paragraph,
+ // so in that special case the output needs to be appended to the
+ // new run's text instead of the previous run
+ if (isAtEndOfParagraph)
+ {
+ // close the fldrslt group
+ m_aRunText->append("}}");
+ // close the field group
+ m_aRunText->append('}');
+ }
+ else
+ {
+ // close the fldrslt group
+ m_aRun->append("}}");
+ // close the field group
+ m_aRun->append('}');
+ }
+ m_sURL.clear();
}
return true;
}
diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx
index a307885d7182..f6b64151f516 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.hxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.hxx
@@ -596,6 +596,9 @@ private:
boost::optional<css::drawing::FillStyle> m_oFillStyle;
+ /// If we're in the process of exporting a hyperlink, then its URL.
+ OUString m_sURL;
+
public:
RtfAttributeOutput(RtfExport& rExport);