This is an automated email from the ASF dual-hosted git repository. damjan pushed a commit to branch AOO41X in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 74eb9fee553bfc2739c7523bac1b787b6ee509f7 Author: Damjan Jovanovic <[email protected]> AuthorDate: Sat Jan 7 20:25:36 2023 +0200 Allow the XLSX Relationship "Target" attribute in _rels/.rels to have superfluous slashes. Fixes: #117672 - Opening XLSX fails when the Relationship "Target" attribute in _rels/.rels has superfluous slashes Patch by: me (cherry picked from commit 3ff2b12a82734e8b46c6f7693a7e1b8eef8ada96) --- main/oox/inc/oox/core/relationshandler.hxx | 4 ++++ main/oox/source/core/filterdetect.cxx | 3 ++- main/oox/source/core/relationshandler.cxx | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/main/oox/inc/oox/core/relationshandler.hxx b/main/oox/inc/oox/core/relationshandler.hxx index 6affee9858..8ceee13276 100644 --- a/main/oox/inc/oox/core/relationshandler.hxx +++ b/main/oox/inc/oox/core/relationshandler.hxx @@ -44,6 +44,10 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + static ::rtl::OUString + removeDuplicateSlashes( + const ::rtl::OUString &path ); + private: RelationsRef mxRelations; }; diff --git a/main/oox/source/core/filterdetect.cxx b/main/oox/source/core/filterdetect.cxx index 5b16df16f1..3c10e600c4 100644 --- a/main/oox/source/core/filterdetect.cxx +++ b/main/oox/source/core/filterdetect.cxx @@ -29,6 +29,7 @@ #include <openssl/evp.h> #include <rtl/digest.h> #include "oox/core/fastparser.hxx" +#include "oox/core/relationshandler.hxx" #include "oox/helper/attributelist.hxx" #include "oox/helper/binaryinputstream.hxx" #include "oox/helper/binaryoutputstream.hxx" @@ -158,7 +159,7 @@ void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs ) { OUString aType = rAttribs.getString( XML_Type, OUString() ); if( aType.equalsAscii( "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" ) ) - maTargetPath = OUString( sal_Unicode( '/' ) ) + rAttribs.getString( XML_Target, OUString() ); + maTargetPath = RelationsFragment::removeDuplicateSlashes( OUString( sal_Unicode( '/' ) ) + rAttribs.getString( XML_Target, OUString() ) ); } OUString FilterDetectDocHandler::getFilterNameFromContentType( const OUString& rContentType ) const diff --git a/main/oox/source/core/relationshandler.cxx b/main/oox/source/core/relationshandler.cxx index 51a0afc12f..a8566b6f28 100644 --- a/main/oox/source/core/relationshandler.cxx +++ b/main/oox/source/core/relationshandler.cxx @@ -79,7 +79,7 @@ Reference< XFastContextHandler > RelationsFragment::createFastChildContext( Relation aRelation; aRelation.maId = aAttribs.getString( XML_Id, OUString() ); aRelation.maType = aAttribs.getString( XML_Type, OUString() ); - aRelation.maTarget = aAttribs.getString( XML_Target, OUString() ); + aRelation.maTarget = removeDuplicateSlashes( aAttribs.getString( XML_Target, OUString() ) ); if( (aRelation.maId.getLength() > 0) && (aRelation.maType.getLength() > 0) && (aRelation.maTarget.getLength() > 0) ) { sal_Int32 nTargetMode = aAttribs.getToken( XML_TargetMode, XML_Internal ); @@ -100,6 +100,30 @@ Reference< XFastContextHandler > RelationsFragment::createFastChildContext( return xRet; } +OUString RelationsFragment::removeDuplicateSlashes( const OUString &path ) +{ + rtl::OUStringBuffer buffer; + bool hadSlash = false; + for ( sal_Int32 i = 0; i < path.getLength(); i++ ) + { + sal_Unicode ch = path[i]; + if ( ch == '/' ) + { + if ( !hadSlash ) + { + hadSlash = true; + buffer.append( sal_Unicode( '/' ) ); + } + } + else + { + hadSlash = false; + buffer.append( ch ); + } + } + return buffer.makeStringAndClear(); +} + // ============================================================================ } // namespace core
