sw/qa/extras/ooxmlexport/data/multi_space_url.fodt | 9 ++++++ sw/qa/extras/ooxmlexport/ooxmlexport20.cxx | 29 +++++++++++++++++++++ sw/source/filter/ww8/wrtw8nds.cxx | 4 +- 3 files changed, 40 insertions(+), 2 deletions(-)
New commits: commit 7bd7085bcfce0b32179197a14189604d4c7478e1 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jan 10 22:39:39 2024 +0600 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Jan 11 03:59:36 2024 +0100 tdf#159110: store URLs to DOCX correctly It must not decode URLs, and must store it percent-encoded. This was wrong since commit 7b0b5cdfeed656b279bc32cd929630d5fc25878b (initial import, 2000-09-18). Commit d68b1b6ae355c92e982ec845216ba459dbdd9e16 (use correct INetURL-Decode enum, 2000-10-20) replaced incorrect "with charset" decoding with another incorrect "unambiguous" decoding. Change-Id: I915897dc2e3eb838fc02b4ac338b3d76fe0477fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161893 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/data/multi_space_url.fodt b/sw/qa/extras/ooxmlexport/data/multi_space_url.fodt new file mode 100644 index 000000000000..3a96582aa71f --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/multi_space_url.fodt @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:p><text:a xlink:type="simple" xlink:href="http://www.example.org/path%20%20with%20%20spaces" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">A sample hyperlink</text:a></text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx index 5f681011eeec..be378107df04 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx @@ -1111,6 +1111,35 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf158971) } } +CPPUNIT_TEST_FIXTURE(Test, testTdf159110) +{ + // Given a text with an URL with multiple spaces + loadAndReload("multi_space_url.fodt"); + + constexpr OUString sExpectedURL = u"http://www.example.org/path%20%20with%20%20spaces"_ustr; + + // Without the fix, this would have failed with + // - Expected: http://www.example.org/path%20%20with%20%20spaces + // - Actual : http://www.example.org/path with spaces + CPPUNIT_ASSERT_EQUAL(sExpectedURL, + getProperty<OUString>(getRun(getParagraph(1), 1), u"HyperLinkURL"_ustr)); + + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + OString sId + = OUStringToOString(getXPath(pXmlDoc, "/w:document/w:body/w:p/w:hyperlink"_ostr, "id"_ostr), + RTL_TEXTENCODING_UTF8); + + xmlDocUniquePtr pXmlRels = parseExport("word/_rels/document.xml.rels"); + + // Without the fix, this would have failed with + // - Expected: http://www.example.org/path%20%20with%20%20spaces + // - Actual : http://www.example.org/path with spaces + // - In <>, attribute 'Target' of '/rels:Relationships/rels:Relationship[@Id='rId2']' incorrect value. + // I.e., the spaces were stored without percent-encoding, and collapsed on import + assertXPath(pXmlRels, "/rels:Relationships/rels:Relationship[@Id='"_ostr + sId + "']", + "Target"_ostr, sExpectedURL); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index c70c78121b8b..39e2f885230b 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -1092,8 +1092,8 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT else { INetURLObject aURL( rUrl, INetProtocol::NotValid ); - sURL = aURL.GetURLNoMark( INetURLObject::DecodeMechanism::Unambiguous ); - sMark = aURL.GetMark( INetURLObject::DecodeMechanism::Unambiguous ); + sURL = aURL.GetURLNoMark( INetURLObject::DecodeMechanism::NONE ); + sMark = aURL.GetMark( INetURLObject::DecodeMechanism::NONE ); INetProtocol aProtocol = aURL.GetProtocol(); if ( aProtocol == INetProtocol::File || aProtocol == INetProtocol::NotValid )