tdf#44196 - Keep relative paths on URL export

Change-Id: I2ee01e6ef1d1d7dbf2dbbf69440567d152e48f96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209326
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
This commit is contained in:
Andreas Heinisch
2026-08-21 12:23:45 +02:00
parent 94b1da6d3f
commit cba9a06b88
3 changed files with 21 additions and 1 deletions
+17
View File
@@ -57,9 +57,26 @@ public:
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), styles.indexOf(".Default"));
}
void testTdf44196_relative_href()
{
loadFromFile(u"tdf44196_relative_href.html",
{
comphelper::makePropertyValue(u"FilterName"_ustr, u"HTML (StarCalc)"_ustr),
});
save(TestFilter::HTML_CALC);
htmlDocUniquePtr pDoc = parseHtml(maTempFile);
CPPUNIT_ASSERT(pDoc);
// Without the fix in place, this test would have failed
// i.e. href attribute would have beend turned into an absolute file
CPPUNIT_ASSERT(!getXPath(pDoc, "//a", "href").startsWith("file:"));
}
CPPUNIT_TEST_SUITE(ScHTMLExportTest);
CPPUNIT_TEST(testHtmlSkipImage);
CPPUNIT_TEST(testTdf155244);
CPPUNIT_TEST(testTdf44196_relative_href);
CPPUNIT_TEST_SUITE_END();
};
@@ -0,0 +1 @@
<a href="link.html">Text</a>
+3 -1
View File
@@ -1396,7 +1396,9 @@ bool ScHTMLExport::WriteFieldText( const EditTextObject* pData )
{
bUrl = true;
rStrm.WriteChar( '<' ).WriteOString( OOO_STRING_SVTOOLS_HTML_anchor ).WriteChar( ' ' ).WriteOString( OOO_STRING_SVTOOLS_HTML_O_href ).WriteOString( "=\"" );
OUT_STR( pURLField->GetURL() );
// tdf#44196 - keep relative paths on URL export
OUT_STR(URIHelper::simpleNormalizedMakeRelative(aBaseURL,
pURLField->GetURL()));
rStrm.WriteOString( "\">" );
OUT_STR( pURLField->GetRepresentation() );
rStrm.WriteOString( "</" ).WriteOString( OOO_STRING_SVTOOLS_HTML_anchor ).WriteChar( '>' );