ofz#4817 Chaos with multiple body tags

Change-Id: I4f2ab3a3be0909176599963c8ca113e3af85c832
Reviewed-on: https://gerrit.libreoffice.org/47159
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 53dc9e5..7376ab2 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -298,6 +298,7 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn,
    m_bInFootEndNoteSymbol( false ),
    m_bIgnoreHTMLComments( bNoHTMLComments ),
    m_bRemoveHidden( false ),
    m_bBodySeen( false ),
    m_pTempViewFrame(nullptr)
{
    m_nEventId = nullptr;
@@ -1257,25 +1258,31 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
    switch( nToken )
    {
    case HtmlTokenId::BODY_ON:
        if( !m_aStyleSource.isEmpty() )
        if (m_bBodySeen)
            eState = SvParserState::Error;
        else
        {
            m_pCSS1Parser->ParseStyleSheet( m_aStyleSource );
            m_aStyleSource.clear();
        }
        if( IsNewDoc() )
        {
            InsertBodyOptions();
            // If there is a template for the first or the right page,
            // it is set here.
            const SwPageDesc *pPageDesc = nullptr;
            if( m_pCSS1Parser->IsSetFirstPageDesc() )
                pPageDesc = m_pCSS1Parser->GetFirstPageDesc();
            else if( m_pCSS1Parser->IsSetRightPageDesc() )
                pPageDesc = m_pCSS1Parser->GetRightPageDesc();

            if( pPageDesc )
            m_bBodySeen = true;
            if( !m_aStyleSource.isEmpty() )
            {
                m_xDoc->getIDocumentContentOperations().InsertPoolItem( *m_pPam, SwFormatPageDesc( pPageDesc ) );
                m_pCSS1Parser->ParseStyleSheet( m_aStyleSource );
                m_aStyleSource.clear();
            }
            if( IsNewDoc() )
            {
                InsertBodyOptions();
                // If there is a template for the first or the right page,
                // it is set here.
                const SwPageDesc *pPageDesc = nullptr;
                if( m_pCSS1Parser->IsSetFirstPageDesc() )
                    pPageDesc = m_pCSS1Parser->GetFirstPageDesc();
                else if( m_pCSS1Parser->IsSetRightPageDesc() )
                    pPageDesc = m_pCSS1Parser->GetRightPageDesc();

                if( pPageDesc )
                {
                    m_xDoc->getIDocumentContentOperations().InsertPoolItem( *m_pPam, SwFormatPageDesc( pPageDesc ) );
                }
            }
        }
        break;
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 1392192..7ba0e42 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -483,6 +483,8 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
    bool m_bIgnoreHTMLComments : 1;
    bool m_bRemoveHidden : 1; // the filter implementation might set the hidden flag

    bool m_bBodySeen : 1;

    /// the names corresponding to the DOCINFO field subtypes INFO[1-4]
    OUString m_InfoNames[4];