diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-12-13 09:49:41 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-12-13 14:44:15 +0100 |
commit | 4af729f31c64c09c76ea8bcfa5067092571b92de (patch) | |
tree | 555e540d0d7564218fc9f31486a59e8119e3cd50 /filter/qa | |
parent | 1d6b85f85925c3b4d2d2bb8eaf237b10bb8f7d60 (diff) |
tdf#114428 filter: recognize XHTML with XML declaration as HTML
The problem was the additional
<?xml version="1.0" encoding="utf-8"?>
XML declaration before the usual
<!DOCTYPE html ...
line, just ignore it.
Change-Id: I294aae5504b40b42f76da00fef645d0d89009da9
Reviewed-on: https://gerrit.libreoffice.org/46324
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'filter/qa')
-rw-r--r-- | filter/qa/unit/data/tdf114428.xhtml | 9 | ||||
-rw-r--r-- | filter/qa/unit/textfilterdetect.cxx | 63 |
2 files changed, 72 insertions, 0 deletions
diff --git a/filter/qa/unit/data/tdf114428.xhtml b/filter/qa/unit/data/tdf114428.xhtml new file mode 100644 index 000000000000..f08f0fa4a028 --- /dev/null +++ b/filter/qa/unit/data/tdf114428.xhtml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>Title of document</title> + </head> + <body>hello world</body> +</html> diff --git a/filter/qa/unit/textfilterdetect.cxx b/filter/qa/unit/textfilterdetect.cxx new file mode 100644 index 000000000000..272ba85b330b --- /dev/null +++ b/filter/qa/unit/textfilterdetect.cxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/io/XInputStream.hpp> + +#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> +#include <test/bootstrapfixture.hxx> +#include <unotools/mediadescriptor.hxx> +#include <unotools/streamwrap.hxx> + +using namespace com::sun::star; + +namespace +{ +/// Test class for PlainTextFilterDetect. +class TextFilterDetectTest : public test::BootstrapFixture +{ +public: + void testTdf114428(); + + CPPUNIT_TEST_SUITE(TextFilterDetectTest); + CPPUNIT_TEST(testTdf114428); + CPPUNIT_TEST_SUITE_END(); +}; + +char const DATA_DIRECTORY[] = "/filter/qa/unit/data/"; + +void TextFilterDetectTest::testTdf114428() +{ + uno::Reference<uno::XComponentContext> xComponentContext + = comphelper::getComponentContext(getMultiServiceFactory()); + uno::Reference<document::XExtendedFilterDetection> xDetect( + getMultiServiceFactory()->createInstance("com.sun.star.comp.filters.PlainTextFilterDetect"), + uno::UNO_QUERY); + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf114428.xhtml"; + SvFileStream aStream(aURL, StreamMode::READ); + uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(aStream)); + uno::Sequence<beans::PropertyValue> aDescriptor + = { comphelper::makePropertyValue("DocumentService", + OUString("com.sun.star.text.TextDocument")), + comphelper::makePropertyValue("InputStream", xStream), + comphelper::makePropertyValue("TypeName", OUString("generic_HTML")) }; + xDetect->detect(aDescriptor); + utl::MediaDescriptor aMediaDesc(aDescriptor); + OUString aFilterName = aMediaDesc.getUnpackedValueOrDefault("FilterName", OUString()); + // This was empty, XML declaration caused HTML detect to not handle XHTML. + CPPUNIT_ASSERT_EQUAL(OUString("HTML (StarWriter)"), aFilterName); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(TextFilterDetectTest); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |