diff --git a/Frameworks/file/src/type.cc b/Frameworks/file/src/type.cc index 39c53f18..6e811d80 100644 --- a/Frameworks/file/src/type.cc +++ b/Frameworks/file/src/type.cc @@ -108,6 +108,10 @@ static std::string find_file_type (std::string const& path, io::bytes_ptr const& if(res == NULL_STR && effectivePath != NULL_STR) res = settings_for_path(effectivePath, "attr.file.unknown-type " + pathAttributes, settingsDirectory).get(kSettingsFileTypeKey, NULL_STR); + // check if file has no extension, if so, treat it as plain text + if(res == NULL_STR && path::extension(effectivePath).empty()) + res = "text.plain"; + return res; } diff --git a/Frameworks/file/tests/t_open.cc b/Frameworks/file/tests/t_open.cc index cfe586c4..ba1f6ff3 100644 --- a/Frameworks/file/tests/t_open.cc +++ b/Frameworks/file/tests/t_open.cc @@ -125,6 +125,21 @@ public: } void test_file_type () + { + test::jail_t jail; + path::set_content(jail.path("test.x-unknown"), "dummy"); + + stall_t* cb = new stall_t(NULL_STR, "x.test"); + file::open_callback_ptr sharedPtr((file::open_callback_t*)cb); + file::open(jail.path("test.x-unknown"), osx::authorization_t(), sharedPtr); + cb->wait(); + + TS_ASSERT_EQUALS(cb->_error, false); + TS_ASSERT_EQUALS(cb->_file_type, "x.test"); + TS_ASSERT_EQUALS(std::string(cb->_content->begin(), cb->_content->end()), "dummy"); + } + + void test_file_type_no_ext () { test::jail_t jail; path::set_content(jail.path("test"), "dummy"); @@ -135,18 +150,18 @@ public: cb->wait(); TS_ASSERT_EQUALS(cb->_error, false); - TS_ASSERT_EQUALS(cb->_file_type, "x.test"); + TS_ASSERT_EQUALS(cb->_file_type, "text.plain"); TS_ASSERT_EQUALS(std::string(cb->_content->begin(), cb->_content->end()), "dummy"); } void test_file_type_failure () { test::jail_t jail; - path::set_content(jail.path("test"), "dummy"); + path::set_content(jail.path("test.x-unknown"), "dummy"); stall_t* cb = new stall_t; file::open_callback_ptr sharedPtr((file::open_callback_t*)cb); - file::open(jail.path("test"), osx::authorization_t(), sharedPtr); + file::open(jail.path("test.x-unknown"), osx::authorization_t(), sharedPtr); cb->wait(); TS_ASSERT_EQUALS(cb->_error, true);