diff options
author | Michael Stahl <mstahl@redhat.com> | 2018-03-01 13:10:40 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-03-14 09:03:34 +0100 |
commit | dab0220f91bcd2dab85309c14bcd10c27639544d (patch) | |
tree | 0e8cbb1f07b8a5e1813e2bc473c437d2e6d2fe6f /xmloff | |
parent | e4c16d917d7cb4c7c220e9e51cd8c4a386317305 (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/50583
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.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 22 |
2 files changed, 21 insertions, 3 deletions
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() ); |