mirror of
https://github.com/php/php-src.git
synced 2026-04-17 21:11:02 +02:00
`buf` may contain NUL bytes, so we must not use `strcspn()` but rather a binary safe variant. However, we also must not detect a stray CR as line ending, and since we only need to check line endings at the end of the buffer, we can nicely optimize. Co-authored-by: Nikita Popov <nikita.ppv@gmail.com> Closes GH-6836.
28 lines
580 B
PHP
28 lines
580 B
PHP
--TEST--
|
|
Bug #80933 (SplFileObject::DROP_NEW_LINE is broken for NUL and CR)
|
|
--FILE--
|
|
<?php
|
|
$lines = [
|
|
"Lorem ipsum \0 dolor sit amet", // string with NUL
|
|
"Lorem ipsum \r dolor sit amet", // string with CR
|
|
];
|
|
foreach ($lines as $line) {
|
|
$temp = new SplTempFileObject();
|
|
$temp->fwrite($line);
|
|
|
|
$temp->rewind();
|
|
$read = $temp->fgets();
|
|
var_dump($line === $read);
|
|
|
|
$temp->rewind();
|
|
$temp->setFlags(SplFileObject::DROP_NEW_LINE);
|
|
$read = $temp->fgets();
|
|
var_dump($line === $read);
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|
|
bool(true)
|