Bug #78043 [NEW]: UTF-8 BOM is carried from an included file into a Header Content
| From: | barryd dot it at gmail dot com | Date: | Mon, 20 May 2019 17:23:50 +0000 |
| Subject: | Bug #78043 [NEW]: UTF-8 BOM is carried from an included file into a Header Content | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-220921@lists.php.net to get a copy of this message | ||
From: barryd dot it at gmail dot com
Operating system: Windows
PHP version: 7.2.18
Package: *Unicode Issues
Bug Type: Bug
Bug description:UTF-8 BOM is carried from an included file into a Header Content
Description:
------------
I included a file into my script, and soon found that since that file
was a UTF-8 encoded file which means that at the beginning of the file,
is a UTF-8 BOM code sitting just before the ...<?php ?> tags, and that
the information which is sent with Content-Disposition: attachment;, and
no matter what my Content-Type: application/rtf;
charset=iso-8859-1//TRANSLIT says, the downloaded content turned out to
be UTF-8 instead of ANSI. The string itself was entirely ASCII. What
needs to be changed is that BOM code needs to be filtered out of the
content, thus ensuring that the content-type can be honored. In order to
recreate this scenario, simply change the include.php files' encoding to
UTF-8, and use the code mentioned below. And once you save the file sent
from the web server to you system, you to will find that the content is
UTF-8.
Test script:
---------------
<?php
include_once('include.php');
$rtf = 'Testing';
header('Content-Type: application/rtf; charset=iso-8859-1//TRANSLIT');
header('Content-Disposition: attachment; filename="' . '10-Jane-Doe' .
'.rtf"');
header('Content-Length: ' . strlen($rtf));
header('Expires: Fri, 01 Jan 2010 05:00:00 GMT');
header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT');
header('Cache-Control: private, must-revalidate');
header('Pragma: no-cache');
ob_start();
echo $rtf;
ob_end_flush();
exit();
?>
Expected result:
----------------
I would expect the web server to honor the Content-Type of the string
and the web browser honor the Encoding of file being downloaded, and not
have php push content not part of the string into the output buffer.
Testing
Actual result:
--------------
â©ââTesting is being downloaded into the rtf file, thus causing the
file to be UTF-8, and then causing the file not to rendered properly
with LibreOffice.
--
Edit bug report at https://bugs.php.net/bug.php?id=78043&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78043&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78043&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78043&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=78043&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78043&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78043&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78043&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78043&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78043&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78043&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78043&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78043&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78043&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78043&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=78043&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78043&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78043&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78043&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78043&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78043&r=mysqlcfg