Opened 12 years ago

Closed 5 years ago

#1705 closed enhancement (fixed)

SVG file identified as text file

Reported by: jackburton Owned by: pulkomandy
Priority: normal Milestone: R1
Component: - General Version: R1/pre-alpha1
Keywords: Cc: EdwinGuy+Haiku@…
Blocked By: Blocking:
Has a Patch: no Platform: All


Go to /boot/beos/etc/artwork, Click with the right mouse button on "lion.svg", choose "Identify". The file will be identified as text file, while should be identified as SVG. This is with hrev23328 built under linux

Change History (8)

comment:1 by bonefish, 12 years ago

Component: Servers/registrar- General
Owner: changed from bonefish to axeld
Type: bugenhancement

We don't have a MIME DB entry for SVG yet (cf. src/data/beos_mime/text/), and the one for XML doesn't have a sniffer rule, so it is absolutely correct that SVN files are identified as text/plain. Feel free to add the MIME DB entry.

comment:2 by RandomInsano, 11 years ago

Cc: EdwinGuy+Haiku@… added

There is a rule now, and the MIME type still doesn't get detected properly. I've tried adapting the HTML SNIFF_RULE for SVG files and either didn't format it properly or it's just broken.

Does anyone know a resource for learning how to write sniff rules? I'd like to look into this more and make the various XML based documents detect properly. I'd also like to poke at the code to see how it determines what mime_type files determine file properties.

Somehow I feel that the extension should really be the definitive decider of which MIME type Haiku needs to set and then if none is present, use a sniff rule. Currently lion.svg or butterfly.svg are detected as text/plain.

Also, SVG allows for the presence of a <head> attributes and other tags that would allow it to be falsely detected as HTML. If the file contains "<!DOCTYPE svg" the mime type should be set to "image\svg+xml" regardless of whatever else is found in the file.

How would you prevent the HTML mime type from getting there first? All sorts of problems with this MIME business... I think the sniff rule needs some documentation

comment:3 by axeld, 11 years ago

The sniffing rules are currently only documented in src/kits/storage/MimeType.cpp, lines 1534ff.

You prevent the HTML MIME type by giving yours a higher priority; you just have to be more sure that you detected an SVG than HTML is.

File extensions are the secondary identifier only, and will definitely stay this way, as they are not reliable (unlike the contents). However, me might need more powerful sniffer rules to catch them all (like OpenOffice documents that are just zip archives with a different suffix).

comment:4 by RandomInsano, 11 years ago

I'd say file extensions prove well in other operating systems, but I agree we shouldn't have to use them. You know best Axel. I think what I'll do instead is poke at those Firefox porting folks and make sure they set the content type of files that are downloaded since the server should tell them in it's header. I'm sure it will solve 90% of complaints about bad detection anyway.

And now I'm off to read source code! :D

comment:5 by un_spacyar, 5 years ago

Actually, Haiku identify .SVG files as "Image Files"; and already exists the entry in "FileTypes" app.

Tested in hrev45740.

I think this ticket must be closed as "Fixed".

comment:6 by diver, 5 years ago

Owner: changed from axeld to pulkomandy
Status: newassigned

comment:7 by pulkomandy, 5 years ago

We do have a rule for SVG now, which detects things reliably with the doctype or the "<svg" tag.

comment:8 by pulkomandy, 5 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.