From b9e5288d103d0a857b1133d2d8e48f3a06c3e0ff Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Thu, 20 Jan 2022 16:00:46 +0100 Subject: [PATCH] detect WordPerfect (#309) --- VERSION | 2 +- include/odr/file.h | 3 +++ src/internal/magic.cpp | 2 ++ src/open_document_reader.cpp | 10 ++++++++++ test/data/input/odr-public | 2 +- test/src/internal/magic_test.cpp | 5 +++++ test/src/output_reference_test.cpp | 1 + 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 50aea0e7a..7c3272873 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.0 \ No newline at end of file +2.1.1 \ No newline at end of file diff --git a/include/odr/file.h b/include/odr/file.h index 7900eaa52..105a58e1d 100644 --- a/include/odr/file.h +++ b/include/odr/file.h @@ -42,6 +42,9 @@ enum class FileType { legacy_powerpoint_presentation, legacy_excel_worksheets, + // https://en.wikipedia.org/wiki/WordPerfect + word_perfect, + // https://en.wikipedia.org/wiki/Rich_Text_Format rich_text_format, diff --git a/src/internal/magic.cpp b/src/internal/magic.cpp index 845ea66b2..26653fb16 100644 --- a/src/internal/magic.cpp +++ b/src/internal/magic.cpp @@ -50,6 +50,8 @@ FileType magic::file_type(const std::string &head) { return FileType::starview_metafile; } else if (match_magic(head, "7B 5C 72 74 66 31")) { return FileType::rich_text_format; + } else if (match_magic(head, "FF 57 50 43")) { + return FileType::word_perfect; } return FileType::unknown; } diff --git a/src/open_document_reader.cpp b/src/open_document_reader.cpp index 1a414d61d..dae893d1f 100644 --- a/src/open_document_reader.cpp +++ b/src/open_document_reader.cpp @@ -49,6 +49,10 @@ OpenDocumentReader::type_by_extension(const std::string &extension) noexcept { return FileType::legacy_powerpoint_presentation; } else if (extension == "xls") { return FileType::legacy_excel_worksheets; + } else if (extension == "wpd") { + return FileType::word_perfect; + } else if (extension == "rtf") { + return FileType::rich_text_format; } else if (extension == "pdf") { return FileType::portable_document_format; } else if (extension == "png") { @@ -88,6 +92,8 @@ OpenDocumentReader::category_by_type(const FileType type) noexcept { case FileType::legacy_word_document: case FileType::legacy_powerpoint_presentation: case FileType::legacy_excel_worksheets: + case FileType::word_perfect: + case FileType::rich_text_format: return FileCategory::document; case FileType::portable_network_graphics: case FileType::graphics_interchange_format: @@ -131,6 +137,10 @@ std::string OpenDocumentReader::type_to_string(const FileType type) noexcept { return "ppt"; case FileType::legacy_excel_worksheets: return "xls"; + case FileType::word_perfect: + return "wpd"; + case FileType::rich_text_format: + return "rtf"; case FileType::portable_document_format: return "pdf"; case FileType::portable_network_graphics: diff --git a/test/data/input/odr-public b/test/data/input/odr-public index 794740b10..a76379399 160000 --- a/test/data/input/odr-public +++ b/test/data/input/odr-public @@ -1 +1 @@ -Subproject commit 794740b10d49836e83d0367815b9787e91f2d522 +Subproject commit a76379399023f697ac156f8e81300e395ad65add diff --git a/test/src/internal/magic_test.cpp b/test/src/internal/magic_test.cpp index 83084495b..44a0beec6 100644 --- a/test/src/internal/magic_test.cpp +++ b/test/src/internal/magic_test.cpp @@ -27,3 +27,8 @@ TEST(magic, odf) { File file(TestData::test_file_path("odr-private/pdf/sample.pdf")); EXPECT_EQ(magic::file_type(*file.impl()), FileType::portable_document_format); } + +TEST(magic, wpd) { + File file(TestData::test_file_path("odr-public/wpd/Sync3 Sample Page.wpd")); + EXPECT_EQ(magic::file_type(*file.impl()), FileType::word_perfect); +} diff --git a/test/src/output_reference_test.cpp b/test/src/output_reference_test.cpp index 35bfc08bd..b22769494 100644 --- a/test/src/output_reference_test.cpp +++ b/test/src/output_reference_test.cpp @@ -43,6 +43,7 @@ TEST_P(OutputReferenceTests, html_meta) { (test_file.type == FileType::legacy_word_document) || (test_file.type == FileType::legacy_powerpoint_presentation) || (test_file.type == FileType::legacy_excel_worksheets) || + (test_file.type == FileType::word_perfect) || (test_file.type == FileType::starview_metafile)) { GTEST_SKIP(); }