View Issue Details

IDProjectCategoryView StatusLast Update
0000647fileGeneralpublic2025-04-24 18:39
Reporterthea Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86_64OSArch LinuxOS Version6.14.3-arch1-1
Product Version5.46 
Summary0000647: Typst Mime Type Detection Error text/vnd.typst
DescriptionI detected an error with the mime type detection of typst source files.
See Issue on github: https://github.com/typst/typst/issues/6174

Currently there is no typst file magic definition.
The typst mime type was registrated here: https://www.iana.org/assignments/media-types/text/vnd.typst

Adding an import like
#import "common.typ"
or
#import "@preview/cetz-plot:0.1.1": plot
will lead to false claim as text/x-objective-c.
It is caused by the defintion found here: https://github.com/file/file/blob/f77a1092e1862c2295a21077c9e28c2614a0eede/magic/Magdir/c-lang#L94-L98

The typst mime type is also defined in the xdg freedesktop definition, but the x-objective-c magic match out wins the xdg definition.
https://gitlab.freedesktop.org/xdg/shared-mime-info/-/blob/master/data/freedesktop.org.xml.in?ref_type=heads#L7782-7787

Steps To Reproduce- create typst source file with imports
- create objective-c source file with import
- run file -i file1.m file2.typ
- file2.typ will be claimed as text/objective-c
Additional InformationI added a sample file for objective-c and typst, as well as a custom magic file, which might be solution.
Run my test with:

> file -m custom.magic -i sample_typst.typ sample_objective_c.m
sample_typst.typ: text/vnd.typst; charset=us-ascii
sample_objective_c.m: text/x-objective-c; charset=us-ascii
Tagsbug, magic

Activities

thea

2025-04-24 18:38

reporter  

custom.magic (536 bytes)   
# Objective-C
0	search/8192	#import
>0	regex	\^#import[[:space:]]+["<]	Objective-C source text
!:strength + 25
!:mime	text/x-objective-c

# Typst
0 regex \^[[:space:]]*#(import|include)[[:space:]]+\"@[[:alnum:]\-]+    Typst source text
!:strength + 10
!:mime	text/vnd.typst
!:ext typ
0 regex \^[[:space:]]*#(import|include)[[:space:]]+\"[[:alnum:]]+.typ\"    Typst source text
!:strength + 10
!:mime	text/vnd.typst
!:ext typ
0 regex \^[[:space:]]*#(set|show|let|if)    Typst source text
!:strength + 10
!:mime	text/vnd.typst
!:ext typ

custom.magic (536 bytes)   
sample_objective_c.m (161 bytes)   
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, Objective-C!");
    }
    return 0;
}
sample_objective_c.m (161 bytes)   
sample_typst.typ (181 bytes)   
#set page(width: 210mm, height: 297mm)

//#import "common.typ"
#import  "@preview/cetz-plot:0.1.1": plot

= Hello, Typst!

This is a simple Typst document using a `#set` directive.
sample_typst.typ (181 bytes)   

Issue History

Date Modified Username Field Change
2025-04-24 18:38 thea New Issue
2025-04-24 18:38 thea File Added: custom.magic
2025-04-24 18:38 thea File Added: sample_objective_c.m
2025-04-24 18:38 thea File Added: sample_typst.typ
2025-04-24 18:38 thea Tag Attached: magic
2025-04-24 18:38 thea Tag Attached: bug