summaryrefslogtreecommitdiff
path: root/xmloff
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 /xmloff
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 'xmloff')
-rw-r--r--xmloff/source/core/xmlictxt.cxx1
-rw-r--r--xmloff/source/core/xmlimp.cxx18
2 files changed, 16 insertions, 3 deletions
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() );