php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79764 finfo::file returns text/plain mime type when JSON contains empty arrays
Submitted: 2020-07-01 12:26 UTC Modified: 2020-07-01 14:10 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: edi dot modric at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 7.4.7 OS: Ubuntu 20.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: edi dot modric at gmail dot com
New email:
PHP Version: OS:

 

 [2020-07-01 12:26 UTC] edi dot modric at gmail dot com
Description:
------------
Using the following JSON document:

{
    "foo": []
}

finfo::file method wrongly returns text/plain as mime type instead of application/json.

Modifying the JSON document to e.g.:

{
    "foo": ["bar"]
}

makes the function behave correctly and returns application/json.

Test script:
---------------
<?php

$finfo = new finfo(FILEINFO_MIME_TYPE);

echo $finfo->file('file.json') . PHP_EOL;


Expected result:
----------------
With the following content of file.json:

{
    "foo": []
}

I expect to see "application/json" as the output.

Actual result:
--------------
With the following content of file.json:

{
    "foo": []
}

"text/plain" is returned.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-01 12:48 UTC] mamontovdmitriy at mail dot ru
I confirm this issue.
 [2020-07-01 13:31 UTC] cmb@php.net
What does `file` report about that file?
 [2020-07-01 13:39 UTC] edi dot modric at gmail dot com
eddie@abyss ~ $ file a.json
a.json: ASCII text

eddie@abyss ~ $ file b.json
b.json: JSON data

So it seems this might not be a PHP issue, but a system one. If so, feel free to close this and sorry for the noise.
 [2020-07-01 14:10 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-07-01 14:10 UTC] cmb@php.net
No problem. :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 19:01:35 2025 UTC