mirror of
https://github.com/php/php-src.git
synced 2026-04-26 09:28:21 +02:00
Fix #80933: SplFileObject::DROP_NEW_LINE is broken for NUL and CR
`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.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
--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)
|
||||
Reference in New Issue
Block a user