[Libreoffice-commits] core.git: svtools/qa svtools/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Aug 29 06:37:35 UTC 2018
svtools/qa/unit/testHtmlReader.cxx | 22 ++++++++++++++++++++++
svtools/source/svhtml/parhtml.cxx | 3 ++-
2 files changed, 24 insertions(+), 1 deletion(-)
New commits:
commit 60362accc78fdff4213fa6c28bb4fbf00e06972f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Tue Aug 28 18:10:03 2018 +0200
Commit: Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Wed Aug 29 08:37:10 2018 +0200
XHTML import: <br></br> 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 <vmiklos at collabora.co.uk>
Tested-by: Jenkins
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<br></br>bbb");
+ aStream.WriteBytes(aDocument.getStr(), aDocument.getLength());
+ aStream.Seek(0);
+
+ tools::SvRef<TestHTMLParser> xParser = new TestHTMLParser(aStream);
+ xParser->SetNamespace("reqif-xhtml");
+ xParser->CallParser();
+
+ // This was 2, <br></br> 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<HtmlTokenId>(static_cast<int>(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 </BR>, that is treated like <BR>)
+ // No exception for XHTML, though.
nRet = HtmlTokenId::UNKNOWNCONTROL_OFF;
}
}
More information about the Libreoffice-commits
mailing list