diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-06-15 18:07:12 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-06-15 18:12:27 +0200 |
commit | b4855bd63c05096df1a2da339133f243bb30d902 (patch) | |
tree | 8aeb90355a3c5dcb9d191d8d87f8ff14b0c4d481 | |
parent | cd7671ef5e3102e91c68588d1ccc39d2521af561 (diff) |
tdf#100105 sw: RTF export: fix empty hyperlinks
For empty hyperlinks the EndURL() is called immediately after StartURL()
Due to the way the various buffers are written, the group closing braces
are written before the groups are opened, which is rather invalid.
Using the m_aRun buffer instead of m_aStyles appears to fix the problem.
(regression from b8907bf3d3b37c686a414ffbbd2d732348aab5b9)
Change-Id: I6910e1afa0ee262ae0496cf1d3aa83ae3e537ad0
-rw-r--r-- | sw/qa/extras/rtfexport/data/hyperlink_empty.rtf | 8 | ||||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport.cxx | 11 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.cxx | 28 |
3 files changed, 33 insertions, 14 deletions
diff --git a/sw/qa/extras/rtfexport/data/hyperlink_empty.rtf b/sw/qa/extras/rtfexport/data/hyperlink_empty.rtf new file mode 100644 index 000000000000..bdd263df06da --- /dev/null +++ b/sw/qa/extras/rtfexport/data/hyperlink_empty.rtf @@ -0,0 +1,8 @@ +{\rtf1 +{\field +{\*\fldinst HYPERLINK "http://example.net"} +{\fldrslt } +} +foobar +\par +} diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 37a70184dcdd..f7a272d035fd 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -523,6 +523,17 @@ DECLARE_RTFEXPORT_TEST(testHyperlink, "hyperlink.rtf") CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(getRun(getParagraph(1), 3, "!"), "HyperLinkURL")); } +DECLARE_RTFEXPORT_TEST(testHyperlinkTdf100105, "hyperlink_empty.rtf") +{ + // export of empty link was invalid, group was closed before it was opened + uno::Reference<text::XTextDocument> xTextDoc(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextCursor> xCursor(xTextDoc->getText()->createTextCursor()); + xCursor->gotoStart(false); + CPPUNIT_ASSERT_EQUAL(OUString("http://example.net"), getProperty<OUString>(xCursor, "HyperLinkURL")); + // getRun doesn't provide a 0-length hyperlink + CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(getRun(getParagraph(1), 1, "foobar"), "HyperLinkURL")); +} + DECLARE_RTFEXPORT_TEST(test78758, "fdo78758.rtf") { CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc264438068"), diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index a0da23528869..4e87ecbf6fe7 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -553,26 +553,26 @@ bool RtfAttributeOutput::StartURL(const OUString& rUrl, const OUString& rTarget) // 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 "); + m_aRun->append('{'); + m_aRun->append(OOO_STRING_SVTOOLS_RTF_FIELD); + m_aRun->append('{'); + m_aRun->append(OOO_STRING_SVTOOLS_RTF_IGNORE); + m_aRun->append(OOO_STRING_SVTOOLS_RTF_FLDINST); + m_aRun->append(" HYPERLINK "); - m_aStyles.append("\""); - m_aStyles.append(msfilter::rtfutil::OutString(rUrl, m_rExport.m_eCurrentEncoding)); - m_aStyles.append("\" "); + m_aRun->append("\""); + m_aRun->append(msfilter::rtfutil::OutString(rUrl, m_rExport.m_eCurrentEncoding)); + m_aRun->append("\" "); if (!rTarget.isEmpty()) { - m_aStyles.append("\\\\t \""); - m_aStyles.append(msfilter::rtfutil::OutString(rTarget, m_rExport.m_eCurrentEncoding)); - m_aStyles.append("\" "); + m_aRun->append("\\\\t \""); + m_aRun->append(msfilter::rtfutil::OutString(rTarget, m_rExport.m_eCurrentEncoding)); + m_aRun->append("\" "); } - m_aStyles.append("}"); - m_aStyles.append("{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {"); + m_aRun->append("}"); + m_aRun->append("{" OOO_STRING_SVTOOLS_RTF_FLDRSLT " {"); } return true; } |