Edit report at https://bugs.php.net/bug.php?id=80933&edit=1
ID: 80933
Updated by: requinix@php.net
Reported by: gabrielpl at gmail dot com
Summary: When flag DROP_NEW_LINE is enabled, line read stops
at null char
-Status: Open
+Status: Verified
Type: Bug
Package: SPL related
Operating System: Windows
PHP Version: 8.0.3
Block user comment: N
Private report: N
New Comment:
Simple naive use of strcspn.
https://github.com/php/php-src/blob/PHP-8.0.3/ext/spl/spl_directory.c#L1891
Previous Comments:
------------------------------------------------------------------------
[2021-04-04 06:15:52] gabrielpl at gmail dot com
Description:
------------
When the flag DROP_NEW_LINE is enabled in SplFileObject classes, reading a line (e.g. fgets()) stops
at null char.
When the flag is disabled, the read operation works as intended.
Test script:
---------------
<?php
// string with a NULL char
$line = "Lorem ipsum \0 dolor sit amet";
$temp = new SplTempFileObject();
$temp->fwrite($line);
$temp->rewind();
$read = $temp->fgets();
echo 'SplFileObject::DROP_NEW_LINE flag -> disabled' . PHP_EOL;
var_dump(strcmp($line, $read), $read);
$temp->rewind();
$temp->setFlags(SplFileObject::DROP_NEW_LINE);
$read = $temp->fgets();
echo PHP_EOL . 'SplFileObject::DROP_NEW_LINE flag -> enabled' . PHP_EOL;
var_dump(strcmp($line, $read), $read);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80933&edit=1