TonyValenti / Mime-Detective-clarkis117

Mime type detector for files, byte arrays, and streams, .NET Standard Fork
MIT License
38 stars 9 forks source link

XML File detected as plain/text #24

Open zerlas opened 6 years ago

zerlas commented 6 years ago

Calling GetFileType(this byte[] bytes) returns "plain/text" instead of "application/xml".

clarkis117 commented 6 years ago

@zerlas Thank you for filing an issue but could you provide a better description, steps to reproduce, and sample data?

zerlas commented 6 years ago

i'm sorry, when i'm trying to get the type of a XML file like this :

var path = Path.Combine(this.TestContext.DeploymentDirectory, "file.smmx"); // this file is a correct XML file
using (var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var stream = new MemoryStream((int)file.Length))
{
    file.CopyTo(stream);
    var streamArray = stream.ToArray();
    var type = streamArray.GetFileType();
    type.ShouldNotBeNull();
    type.Mime.ShouldEqual("application/xml"); // this line crash because type.Mime == "plain/text"
}

This line : type.Mime.ShouldEqual("application/xml"); Crash because it return the type "plain/text"

clarkis117 commented 6 years ago

@zerlas Hmmm.... Given that XML files are plain text it may be matching on a Unicode byte order mark. Have you tried this file with the beta version of the library?

zerlas commented 6 years ago

i'm already on the last beta version : 0.0.6 beta4

sandrock commented 6 years ago

Here are the first bytes of a problematic XML file on my side. Using nuget 0.0.6-beta4.

efbb bf3c 3f78 6d6c 2076 6572 7369 6f6e  ...<?xml version
3d22 312e 3022 2065 6e63 6f64 696e 673d  ="1.0" encoding=
2255 5446 2d38 223f 3e0d 0a3c 2144 4f43  "UTF-8"?>..<!DOC
5459 5045 2073 696d 706c 656d 696e 642d  TYPE simplemind-
sandrock commented 5 years ago

This has been fixed. The issue can be closed.