Fix bug where fgets incorrectly handles \r when at end of chunk.
commit01c4ea4cfd54f272780fe7971e6fd8bc06333e8d
authorScott Hovestadt <scotthovestadt@fb.com>
Mon, 1 Aug 2022 15:42:09 +0000 (1 08:42 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 1 Aug 2022 15:42:09 +0000 (1 08:42 -0700)
treea5844554a7ae890e30ae6d6e41ebc2fdb0367084
parentef4eb29f51f9027b52ae9df32bede94b347ac383
Fix bug where fgets incorrectly handles \r when at end of chunk.

Summary:
Currently, when fgets see `\r` at the end of a chunk, it ignores it because it's worried that the next character will be `\n`. While that strategy correctly handles `\r\n`, it means that `\r` without `\n` is ignored and fgets will return 2 lines instead of 1.

In this diff, I fix the bug by:
- Removing the logic to ignore `\r` when at end of chunk.
- Preventing a situation where a chunk has incomplete information; chunks will never end on `\r` unless we're at end of file.

Reviewed By: ricklavoie

Differential Revision: D38297477

fbshipit-source-id: 37c9ad6befef7f03e037a2a9ac9a37d5ee112179
hphp/runtime/base/file.cpp
hphp/test/slow/file/fgets-cr.php [new file with mode: 0644]
hphp/test/slow/file/fgets-cr.php.expect [new file with mode: 0644]