Page MenuHomePhabricator

CustomMimeType returns wrong extension if this is substring of some other associated extension
Closed, WontfixPublic

Description

Like for the Diffusion image mime type, where both ".hdwi" and ".dwi" are registered file endings, however the

std::string CustomMimeType::ParsePathForExtension(...) returns the ".dwi" extension and not the ".hdwi". This happens because of the string comparison is based on substring matching without the "." at the beginning. Hence while iterating over the extensions (with iter), the

FindCaseInsensitive cmp(*iter);

function retuns a 'hit' already for *iter = "dwi"

Fix proposal:

Use

FindCaseInsensitive cmp("."+*iter);

instead. See attached patch.

Event Timeline

An additional check on the length of the requested substring has to be done, otherwise a std::exception is thrown when std::string::substr( -1 ) is called.

With this fix, however, the mitkPointSetReaderTest is still failing (the reader is not recognized) since the test is asking for

readerRegistry.GetReaders(mitk::FileReaderRegistry::GetMimeTypeForFile("mps"));

Which then does not match by the "."+"mps" expression. So we need to clarify, whether the test is asking for a MimeType with an invalid path and hence returning 'false' is valid here, or not.

The API of the method is as follows

FileReaderRegistry::GetMimeTypeForFile(const std::string& path, us::ModuleContext*)

and similarly for the affected method itself

CustomMimeType::ParsePathForExtension(const std::string& path, std::string& extension, std::string& filename ) const

This can be interpreted in a way that the "path" string should contain a valid path ( i.e. including the extension ) which is not the case for the PointSetTest.

Removed CM-Flag until this is solved just to be on the safe side. :)

kislinsk claimed this task.
kislinsk added a project: Auto-closed.

Hi there! 🙂

This task was auto-closed according to our Task Lifecycle Management.
Please follow this link for more information and don't forget that you are encouraged to reasonable re-open tasks to revive them. 🚑

Best wishes,
The MITK devs

kislinsk removed kislinsk as the assignee of this task.May 26 2020, 12:05 PM
kislinsk removed a subscriber: kislinsk.