[Libreoffice-commits] core.git: include/sax sd/qa xmloff/source
Michael Stahl
mstahl at redhat.com
Thu Mar 1 19:58:36 UTC 2018
include/sax/fastattribs.hxx | 3 ++-
sd/qa/unit/data/unknown-attribute.fodp | 26 ++++++++++++++++++++++++++
sd/qa/unit/export-tests.cxx | 26 ++++++++++++++++++++++++++
xmloff/source/core/xmlictxt.cxx | 1 +
xmloff/source/core/xmlimp.cxx | 18 +++++++++++++++---
5 files changed, 70 insertions(+), 4 deletions(-)
New commits:
commit 700ed27678d688b1afdb4d1759dcd4b078898a3a
Author: Michael Stahl <mstahl at redhat.com>
Date: Thu Mar 1 14:39:56 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.
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 at libreoffice.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx
index 1f343a7235b9..b5fbe225ee28 100644
--- a/include/sax/fastattribs.hxx
+++ b/include/sax/fastattribs.hxx
@@ -82,7 +82,8 @@ public:
void add( sal_Int32 nToken, const sal_Char* pValue, size_t nValueLength );
void add( sal_Int32 nToken, const OString& rValue );
void addNS( sal_Int32 nNamespaceToken, sal_Int32 nToken, const OString& rValue );
- void addUnknown( const OUString& rNamespaceURL, const OString& rName, const OString& value );
+ // note: rQName is *namespace-prefixed*
+ void addUnknown( const OUString& rNamespaceURL, const OString& rQName, const OString& value );
void addUnknown( const OString& rName, const OString& value );
const std::vector< sal_Int32 >& getFastAttributeTokens() const { return maAttributeTokens; }
const char* getFastAttributeValue(size_t nIndex) const { return mpChunk + maAttributeValues[nIndex]; }
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 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);
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index b0494250316f..7d2cc23d9372 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -107,6 +107,7 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamesp
{
const OUString& rAttrValue = unknownAttribs[i].Value;
const OUString& rAttrName = unknownAttribs[i].Name;
+ // note: rAttrName is expected to be namespace-prefixed here
mrImport.maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
}
}
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 758bfc36ac03..b23cec574e8d 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -2265,15 +2265,27 @@ void SAL_CALL SvXMLLegacyToFastDocHandler::startElement( const OUString& rName,
for( sal_Int16 i=0; i < nAttrCount; i++ )
{
OUString aLocalAttrName;
+ 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, nullptr, &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 ) | SvXMLImport::xTokenHandler->getTokenFromUTF8( aAttrSeq ) ;
- mxFastAttributes->add( nAttr, OUStringToOString( rAttrValue, RTL_TEXTENCODING_UTF8 ).getStr() );
+ auto const nToken(SvXMLImport::xTokenHandler->getTokenFromUTF8(aAttrSeq));
+ if (nToken == xmloff::XML_TOKEN_INVALID)
+ {
+ mxFastAttributes->addUnknown(aNamespace,
+ OUStringToOString(rAttrName, 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