Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2046,8 +2046,13 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent) /
intern->u.file.current_line_len = 0;
} else {
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_DROP_NEW_LINE)) {
line_len = strcspn(buf, "\r\n");
buf[line_len] = '\0';
if (line_len > 0 && buf[line_len - 1] == '\n') {
line_len--;
if (line_len > 0 && buf[line_len - 1] == '\r') {
line_len--;
}
buf[line_len] = '\0';
}
}

intern->u.file.current_line = buf;
Expand Down
27 changes: 27 additions & 0 deletions ext/spl/tests/bug80933.phpt
Original file line number Diff line number Diff line change
@@ -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)