From 60362accc78fdff4213fa6c28bb4fbf00e06972f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 28 Aug 2018 18:10:03 +0200 Subject: XHTML import:

is one line break But only for XHTML, HTML stays unchanged to be in sync with web browsers. Change-Id: I3a1cf6651dab565bafece68963acb112ae715cdd Reviewed-on: https://gerrit.libreoffice.org/59727 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- svtools/qa/unit/testHtmlReader.cxx | 22 ++++++++++++++++++++++ svtools/source/svhtml/parhtml.cxx | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/svtools/qa/unit/testHtmlReader.cxx b/svtools/qa/unit/testHtmlReader.cxx index b09abaaabdd5..6df6b5541c2d 100644 --- a/svtools/qa/unit/testHtmlReader.cxx +++ b/svtools/qa/unit/testHtmlReader.cxx @@ -22,8 +22,11 @@ class TestHTMLParser : public HTMLParser public: TestHTMLParser(SvStream& rStream); virtual void NextToken(HtmlTokenId nToken) override; + /// Make this public for test purposes. + using HTMLParser::SetNamespace; OUString m_aDocument; + int m_nLineBreakCount = 0; }; TestHTMLParser::TestHTMLParser(SvStream& rStream) @@ -35,6 +38,8 @@ void TestHTMLParser::NextToken(HtmlTokenId nToken) { if (nToken == HtmlTokenId::TEXTTOKEN) m_aDocument += aToken; + else if (nToken == HtmlTokenId::LINEBREAK) + ++m_nLineBreakCount; } /// Tests HTMLParser. @@ -42,9 +47,11 @@ class Test : public CppUnit::TestFixture { public: void testTdf114428(); + void testLineBreak(); CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(testTdf114428); + CPPUNIT_TEST(testLineBreak); CPPUNIT_TEST_SUITE_END(); }; @@ -63,6 +70,21 @@ void Test::testTdf114428() CPPUNIT_ASSERT_EQUAL(OUString("hello"), xParser->m_aDocument.trim()); } +void Test::testLineBreak() +{ + SvMemoryStream aStream; + OString aDocument("aaa

bbb"); + aStream.WriteBytes(aDocument.getStr(), aDocument.getLength()); + aStream.Seek(0); + + tools::SvRef xParser = new TestHTMLParser(aStream); + xParser->SetNamespace("reqif-xhtml"); + xParser->CallParser(); + + // This was 2,

was interpreted as 2 line breaks in XHTML mode. + CPPUNIT_ASSERT_EQUAL(1, xParser->m_nLineBreakCount); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx index 14ed546ca9fe..c80fd00d77ed 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -1120,10 +1120,11 @@ HtmlTokenId HTMLParser::GetNextToken_() // and there is an off token, return off token instead nRet = static_cast(static_cast(nRet) + 1); } - else if( HtmlTokenId::LINEBREAK!=nRet ) + else if( HtmlTokenId::LINEBREAK!=nRet || !maNamespace.isEmpty()) { // and there is no off token, return unknown token. // (except for
, that is treated like
) + // No exception for XHTML, though. nRet = HtmlTokenId::UNKNOWNCONTROL_OFF; } } -- cgit