[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - sd/qa xmloff/source
Michael Stahl
mstahl at redhat.com
Wed Mar 14 08:03:57 UTC 2018
sd/qa/unit/data/unknown-attribute.fodp | 26 ++++++++++++++++++++++++++
sd/qa/unit/export-tests.cxx | 26 ++++++++++++++++++++++++++
xmloff/source/core/xmlictxt.cxx | 2 ++
xmloff/source/core/xmlimp.cxx | 22 +++++++++++++++++++---
4 files changed, 73 insertions(+), 3 deletions(-)
New commits:
commit dab0220f91bcd2dab85309c14bcd10c27639544d
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Mar 1 13:10:40 2018 +0100
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.
One surprising aspect is that the maNamespaceURL in struct
UnknownAttribute stores the namespace prefix in the libreoffice-5-4
branch, as it lacks commit bb59a80ee6000d3922fa95262f67e291fd9d8ee2.
The attributes are read and converted again in
SvXMLImportContext::startUnknownElement().
Change-Id: Id081c677286a77ec50d9884cdbd9135cf4f6e5b6
Reviewed-on: https://gerrit.libreoffice.org/50583
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
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:oas
is: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 10590131e939..294312f3c2a4 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -87,6 +87,7 @@ public:
void testTdf97630();
void testSwappedOutImageExport();
void testOOoXMLAnimations();
+ void testUnknownAttributes();
void testTdf80020();
void testLinkedGraphicRT();
void testImageWithSpecialID();
@@ -107,6 +108,7 @@ public:
CPPUNIT_TEST(testTdf97630);
CPPUNIT_TEST(testSwappedOutImageExport);
CPPUNIT_TEST(testOOoXMLAnimations);
+ CPPUNIT_TEST(testUnknownAttributes);
CPPUNIT_TEST(testTdf80020);
CPPUNIT_TEST(testLinkedGraphicRT);
CPPUNIT_TEST(testImageWithSpecialID);
@@ -138,6 +140,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)
{
@@ -458,6 +462,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);
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index 63025083d78f..158ba094b60c 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -111,6 +111,8 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix,
{
const OUString& rAttrValue = unknownAttribs[i].Value;
OUString sAttrName = unknownAttribs[i].Name;
+ // NOTE: in *this* release branch, the NamespaceURL is *not*
+ // the URL, but the *prefix*!
const OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL;
if ( !rAttrNamespacePrefix.isEmpty() )
sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index eba9d2ad21b6..334419ade958 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -2134,15 +2134,31 @@ void SAL_CALL SvXMLLegacyToFastDocHandler::startElement( const OUString& rName,
for( sal_Int16 i=0; i < nAttrCount; i++ )
{
OUString aLocalAttrName;
+ OUString aPrefix;
+ OUString aNamespace;
const OUString& rAttrName = xAttrList->getNameByIndex( i );
const OUString& rAttrValue = xAttrList->getValueByIndex( i );
- sal_uInt16 nAttrPrefix = mrImport->mpNamespaceMap->GetKeyByAttrName( rAttrName, &aLocalAttrName );
+ sal_uInt16 const nAttrPrefix(mrImport->mpNamespaceMap->GetKeyByAttrName(
+ rAttrName, &aPrefix, &aLocalAttrName, &aNamespace));
if( XML_NAMESPACE_XMLNS != nAttrPrefix )
{
Sequence< sal_Int8 > aAttrSeq( reinterpret_cast<sal_Int8 const *>(
OUStringToOString( aLocalAttrName, RTL_TEXTENCODING_UTF8 ).getStr()), aLocalAttrName.getLength() );
- sal_Int32 nAttr = NAMESPACE_TOKEN( nAttrPrefix ) | mrImport->mxTokenHandler->getTokenFromUTF8( aAttrSeq ) ;
- mxFastAttributes->add( nAttr, OUStringToOString( rAttrValue, RTL_TEXTENCODING_UTF8 ).getStr() );
+ auto const nToken(mrImport->mxTokenHandler->getTokenFromUTF8(aAttrSeq));
+ if (nToken == xmloff::XML_TOKEN_INVALID)
+ {
+ // NOTE: in *this* release branch, the NamespaceURL is *not*
+ // the URL, but the *prefix*! see
+ // sax_fastparser::FastSaxParserImpl::callbackStartElement 1181
+ mxFastAttributes->addUnknown(aPrefix,
+ OUStringToOString(aLocalAttrName, RTL_TEXTENCODING_UTF8),
+ OUStringToOString(rAttrValue, RTL_TEXTENCODING_UTF8));
+ }
+ else
+ {
+ sal_Int32 const nAttr = NAMESPACE_TOKEN(nAttrPrefix) | nToken;
+ mxFastAttributes->add(nAttr, OUStringToOString(rAttrValue, RTL_TEXTENCODING_UTF8).getStr());
+ }
}
}
mrImport->startFastElement( mnElement, mxFastAttributes.get() );
More information about the Libreoffice-commits
mailing list