ahupp / python-magic

A python wrapper for libmagic
Other
2.66k stars 283 forks source link

Magic can't differentiate between c++ header and source files #274

Closed winwinashwin closed 2 years ago

winwinashwin commented 2 years ago

Description

Not sure if this is really a bug, when trying to guess mimetype of c++ source files, magic returns text/x-c++. Same happens for header files as well. But as per mime-support standard shouldn't the output be text/x-c++src and text/x-c++hdr respectively? Ref: Check lines #768 and #769 of /etc/mime.types

To Reproduce

import magic

print(magic.from_file('main.cpp', mime=True))

Output: text/x-c++

/*
 * @file main.cpp
 */
#include <iostream>

class _ {};

int main() {
  std::cout << "Hello World!" << std::endl;
}
ahupp commented 2 years ago

This is a question for libmagic, which actually implements the filetype identification. But in general this seems like a hard thing to distinguish since they are syntactically the same and only differ by extension and convention.