Skip to content

Commit

Permalink
detect WordPerfect (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Jan 20, 2022
1 parent 4504426 commit b9e5288
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.1.1
3 changes: 3 additions & 0 deletions include/odr/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 2 additions & 0 deletions src/internal/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions src/open_document_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/data/input/odr-public
5 changes: 5 additions & 0 deletions test/src/internal/magic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions test/src/output_reference_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit b9e5288

Please sign in to comment.