Home » Tools and Utilities » MIME_Type » Bug #6095
Parameters and comments parsing buggy
Details
| Submitted | 2005-11-28 12:50 UTC |
|---|---|
| From | t dot broyer at gmail dot com |
| Assigned | cweiske |
| Status | Closed |
| Package | MIME_Type |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-11-28 12:50 UTC] t dot broyer at gmail dot com
Description:
------------
When parsing parameters, comments are only detected after the parameter value, whereas RFC2045, section 5.1 (calling rules of RFC822, section 3.1.4) explicitely allows them anywhere.
These are all valid Content-Type field values:
(UTF-8 Plain Text) text / plain ; charset = utf-8
text (Text) / plain ; charset = utf-8
text / (Plain) plain ; charset = utf-8
text / plain (Plain Text) ; charset = utf-8
text / plain ; (Charset=utf-8) charset = utf-8
text / plain ; charset (Charset) = utf-8
text / plain ; charset = (UTF8) utf-8
text / plain ; charset = utf-8 (UTF-8 Plain Text)
Moreover, stripping of comments will also corrupt parameter values containing an opening parenthesis, e.g.
application/x-foobar;description="bbgh(kdur"
will be parsed as:
- media = application
- subtype = x-foobar
- parameters:
- description = bbgh
And, finally, parsing of quoted-string parameter values has another bug: when the value ends with a quoted <">, the <"> will be stripped. E.g. the parameter value in:
application/x-foobar;description="a \"quoted string\""
will be parsed as (enclosed in angle brackets) <a \"quoted string> instead of <a \"quoted string\"> (or, better: <a "quoted string">)
[2005-11-28 13:07 UTC] t dot broyer at gmail dot com
Test script:
------------
$tests = array(
'(UTF-8 Plain Text) text / plain ; charset = utf-8',
'text (Text) / plain ; charset = utf-8',
'text / (Plain) plain ; charset = utf-8',
'text / plain (Plain Text) ; charset = utf-8',
'text / plain ; (Charset=utf-8) charset = utf-8',
'text / plain ; charset (Charset) = utf-8',
'text / plain ; charset = (UTF8) utf-8',
'text / plain ; charset = utf-8 (UTF-8 Plain Text)',
'application/x-foobar;description="bbgh(kdur"',
'application/x-foobar;description="a \\"quoted string\\""'
);
foreach ($tests as $test) {
print($test . "\n => ");
$mediaType =& new MIME_Type($test);
print($mediaType->get() . "\n\n");
}
Expected result:
----------------
(UTF-8 Plain Text) text / plain ; charset = utf-8
=> text/plain; charset="utf-8"
text (Text) / plain ; charset = utf-8
=> text/plain; charset="utf-8"
text / (Plain) plain ; charset = utf-8
=> text/plain; charset="utf-8"
text / plain (Plain Text) ; charset = utf-8
=> text/plain; charset="utf-8"
text / plain ; (Charset=utf-8) charset = utf-8
=> text/plain; charset="utf-8" (Charset=utf-8)
text / plain ; charset (Charset) = utf-8
=> text/plain; charset="utf-8" (Charset)
text / plain ; charset = (UTF8) utf-8
=> text/plain; charset="utf-8" (UTF8)
text / plain ; charset = utf-8 (UTF-8 Plain Text)
=> text /plain; charset="utf-8" (UTF-8 Plain Text)
application/x-foobar;description="bbgh(kdur"
=> application/x-foobar; description="bbgh(kdur"
application/x-foobar;description="a \"quoted string\""
=> application/x-foobar; description="a \"quoted string\""
Actual result:
--------------
(UTF-8 Plain Text) text / plain ; charset = utf-8
=> (utf-8 plain text) text /plain; charset="utf-8"
text (Text) / plain ; charset = utf-8
=> text (text) /plain; charset="utf-8"
text / (Plain) plain ; charset = utf-8
=> text /(plain) plain; charset="utf-8"
text / plain (Plain Text) ; charset = utf-8
=> text /plain (plain text); charset="utf-8"
text / plain ; (Charset=utf-8) charset = utf-8
=> text /plain; (Charset="" (Charset=utf-8) charset = utf-8)
text / plain ; charset (Charset) = utf-8
=> text /plain; charset (Charset)="" (Charset) = utf-8)
text / plain ; charset = (UTF8) utf-8
=> text /plain; charset="" (UTF8) utf-8)
text / plain ; charset = utf-8 (UTF-8 Plain Text)
=> text /plain; charset="utf-8" (UTF-8 Plain Text)
application/x-foobar;description="bbgh(kdur"
=> application/x-foobar; description="bbgh" (kdur")
application/x-foobar;description="a \"quoted string\""
=> application/x-foobar; description="a \"quoted string\"