Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 426183

Summary: Content type lookup fails for extensions containing a dot "."
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: ClientAssignee: Curtis Windatt <curtis.windatt.public>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public
Version: 5.0   
Target Milestone: 7.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Fix none

Description Mark Macdonald CLA 2014-01-20 15:01:14 EST
I tried to register a content type for Typescript definition files, which end in ".d.ts":

> registerService("orion.core.contenttype", {}, {
>   id: "text/x-typescript-definition",
>   extension: [ "d.ts" ]
> });

However, the ContentTypeRegistry does not recognize any file (eg "foo.d.ts") as having the type given above. To determine a file extension, it examines the segment following the final ".", so 
> extension("foo.d.ts") == "ts"
even if no content type actually registers "ts" anywhere.

The algorithm should be changed to consult the available extensions, as follows
- Take the suffix of filename starting from the initial "."
- Check registry for a contentType with matching extension
- If no match, pop off the leading dot-segment and repeat previous step
- If no more segments return null

This will cause longer extensions to match first, so if both extensions "ts" and "d.ts" are registered to separate content types, we obtain
> extension("foo.d.ts") == "d.ts"
as desired.
Comment 1 Curtis Windatt CLA 2014-09-17 17:26:01 EDT
Created attachment 247175 [details]
Fix
Comment 2 Curtis Windatt CLA 2014-09-17 17:30:23 EDT
The attached patch fixes the problem and adds tests for it.  However, I am getting numerous errors when self hosting.  They should be unrelated, but I don't want to commit this change without testing the large existing suite of content types.

I am updating the wiki to reflect the change.

The logic used is:
1) Loop through all content types, if a filename match is found, break immediately, otherwise if an extension matches the longest possible extension (first dot in the filename), use it.
2) Reduce the extension size compared, segment by segment, each time looping through the content types, break if a match is found.
Comment 3 Curtis Windatt CLA 2014-09-17 17:41:25 EDT
We check the content type for every file visible in the navigator and for each we check every content type registered (>30).  Add in checking extensions segment by segment (directories often use dots as package names), and this is a lot of iterations.

1) Short circuit when a filename match is found (this is done in my patch)
2) Recognize directories as such, and not query the content types.
Comment 4 Curtis Windatt CLA 2014-09-18 15:37:18 EDT
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=41298cbaf822d0241f0ffdadcba1821b1ab3ac30
Fixed in master

I was able to test correctly after logging out, logging back in, clearing the browser resources and restarting my site.  No problems with the content types.
Comment 5 Curtis Windatt CLA 2014-09-18 15:56:52 EDT
I opened Bug 444531 to continue the discussion of content type checking for directories.