summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2018-03-01 13:10:40 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-03-07 13:17:04 +0100
commit316501e04218e86c1e97a0fa606727d0fa989eaa (patch)
tree2ed49879613c021bf362558eb5091e7dadf47f66 /xmloff
parent45d59e98f4905475648d5e3ccacfa1279eb69a18 (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. 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/50589 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/core/xmlictxt.cxx2
-rw-r--r--xmloff/source/core/xmlimp.cxx22
2 files changed, 21 insertions, 3 deletions
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index e1805057dcdd..cc5f46ce0c48 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -113,6 +113,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 f96940aeb575..324fbc0dd4e9 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -2212,15 +2212,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 ) | 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)
+ {
+ // 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() );