6.0.0-beta1
9/18/25

[#2507] MIME, analyzeFile limited regexp fails to recognize valid mime-types
Summary MIME, analyzeFile limited regexp fails to recognize valid mime-types
Queue Horde Framework Packages
Queue Version FRAMEWORK_3
Type Bug
State Resolved
Priority 1. Low
Owners
Requester leena.heino (at) uta (dot) fi
Created 08/24/2005 (7330 days ago)
Due
Updated 08/30/2005 (7324 days ago)
Assigned
Resolved 08/24/2005 (7330 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
08/30/2005 05:52:58 PM leena (dot) heino (at) uta (dot) fi Comment #5 Reply to this comment
You are right, I should have tried to keep the regexp simple.



Should the regexp try to match to a mime-type that has whitespace around it.


08/30/2005 03:06:22 PM Michael Slusarz Comment #4 Reply to this comment
If your file command is turly returning text/.--..-...-..-., then you 
have much larger problems than this regexp matching the MIME type.   
file is either going to return an error string - which won't come 
anywhere close to matching the regexp - or a MIME type which the 
current regexp matches fine.
08/25/2005 05:20:24 AM leena (dot) heino (at) uta (dot) fi Comment #3 Reply to this comment
Cleaned up the regexp a bit and committed to HEAD and FRAMEWORK_3.
Thanks, but now the cleaned up regexp might match invalid mime-types 
like text/.--..-...-..-.


08/24/2005 11:15:33 PM Michael Slusarz Comment #2
State ⇒ Resolved
Reply to this comment
Cleaned up the regexp a bit and committed to HEAD and FRAMEWORK_3.
08/24/2005 06:10:29 PM leena (dot) heino (at) uta (dot) fi Comment #1
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Type ⇒ Bug
Summary ⇒ MIME, analyzeFile limited regexp fails to recognize valid mime-types
Queue ⇒ Horde Framework Packages
Reply to this comment
In MIME package and in analyzeFile() function there is this snippet of code:

...

                 if (preg_match('|^[a-z0-9]+/[a-z0-9]+$|', $type)) {

                     return $type;

                 }

...



This regexp to check mime-type seems very limited and does not seem to 
match to a valid mime-type like application/octet-stream.



I would suggest something like this:

if(preg_match('|^[a-z0-9]+/[a-z0-9]+(?:[.-][a-z0-9]+)*$|i', $type)) {

...

}

Saved Queries