summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2018-03-01 14:39:56 +0100
committerMichael Stahl <mstahl@redhat.com>2018-03-01 20:58:09 +0100
commit700ed27678d688b1afdb4d1759dcd4b078898a3a (patch)
tree4e0d01c203c07eccb3908b03948055c2b3c5bd66 /sd
parent3efd6b5b83364270d2982a0e99bee10f935a793b (diff)
tdf#115429 xmloff: ODF import: fix handling of unknown attributes
... in SvXMLLegacyToFastDocHandler::startElement(), so that it does not create invalid "-1" tokens that end up stored as empty-string attribute names in SvXMLAttrCollection and ultimately exported as invalid XML. The maName in struct UnknownAttribute actually stores a QName, i.e. namespace-prefixed, since commit bb59a80ee6000d3922fa95262f67e291fd9d8ee2. The attributes are read and converted again in SvXMLImportContext::startUnknownElement(). Change-Id: Ia69a4da293f1a84ce30766abc09ca19e2620edbd Reviewed-on: https://gerrit.libreoffice.org/50580 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/qa/unit/data/unknown-attribute.fodp26
-rw-r--r--sd/qa/unit/export-tests.cxx26
2 files changed, 52 insertions, 0 deletions
diff --git a/sd/qa/unit/data/unknown-attribute.fodp b/sd/qa/unit/data/unknown-attribute.fodp
new file mode 100644
index 000000000000..3aa39b666610
--- /dev/null
+++ b/sd/qa/unit/data/unknown-attribute.fodp
@@ -0,0 +1,26 @@
+<?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.presentation">
+ <office:styles>
+
+ </office:styles>
+ <office:automatic-styles>
+
+ <style:style style:name="gr1" style:family="graphic">
+ <style:graphic-properties svg:stroke-color="#000000" draw:fill="solid" draw:fill-color="#008000"
+ svg:fill-rule="evenodd"
+ svg:non-existent-attr="blah"
+ xmlns:foo="http://example.com/" foo:non-existent-att="bar"
+ />
+ </style:style>
+
+ </office:automatic-styles>
+ <office:body>
+ <office:presentation>
+
+ <draw:page>
+ <draw:polygon draw:style-name="gr1" svg:width="3.2cm" svg:height="2cm" svg:x="4cm" svg:y="11.7cm" svg:viewBox="0 0 3201 2001" draw:points="0,2001 3201,2001 3201,0 0,0"/>
+ </draw:page>
+
+ </office:presentation>
+ </office:body>
+</office:document>
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index d1d9e24c7ef4..d1f5a4e2097d 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -82,6 +82,7 @@ public:
void testTdf97630();
void testSwappedOutImageExport();
void testOOoXMLAnimations();
+ void testUnknownAttributes();
void testTdf80020();
void testLinkedGraphicRT();
void testImageWithSpecialID();
@@ -103,6 +104,7 @@ public:
CPPUNIT_TEST(testTdf97630);
CPPUNIT_TEST(testSwappedOutImageExport);
CPPUNIT_TEST(testOOoXMLAnimations);
+ CPPUNIT_TEST(testUnknownAttributes);
CPPUNIT_TEST(testTdf80020);
CPPUNIT_TEST(testLinkedGraphicRT);
CPPUNIT_TEST(testImageWithSpecialID);
@@ -135,6 +137,8 @@ public:
{ "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0" },
{ "xlink", "http://www.w3c.org/1999/xlink" },
{ "loext", "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" },
+ // user-defined
+ { "foo", "http://example.com/" },
};
for (size_t i = 0; i < SAL_N_ELEMENTS(namespaces); ++i)
{
@@ -517,6 +521,28 @@ void SdExportTest::testOOoXMLAnimations()
assertXPath(pXmlDoc, "//anim:par", 223);
}
+void SdExportTest::testUnknownAttributes()
+{
+ ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/unknown-attribute.fodp"), FODP);
+
+ uno::Reference<lang::XComponent> xComponent(xDocShRef->GetModel(), uno::UNO_QUERY);
+ uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(getFormat(ODP)->pFilterName), RTL_TEXTENCODING_UTF8);
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+
+ xDocShRef->DoClose();
+
+ xmlDocPtr pXmlDoc = parseExport(aTempFile, "content.xml");
+ assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/style:graphic-properties[@foo:non-existent-att='bar']");
+// TODO: if the namespace is *known*, the attribute is not preserved, but that seems to be a pre-existing problem, or maybe it's even intentional?
+// assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/style:graphic-properties[@svg:non-existent-att='blah']");
+ // this was on style:graphic-properties on the import, but the export moves it to root node which is OK
+ assertXPathNSDef(pXmlDoc, "/office:document-content", "foo", "http://example.com/");
+}
+
void SdExportTest::testTdf80020()
{
::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/tdf80020.odp"), ODP);