Skip to content

Commit e392d00

Browse files
Address latest comment
1 parent f0e3236 commit e392d00

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

ext/standard/file.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -641,26 +641,11 @@ PHP_FUNCTION(file)
641641
p++;
642642
parse_eol:
643643
if (skip_blank_lines) {
644-
size_t eol_len = 1;
645-
646-
if (eol_marker == '\n') {
647-
if (p - ZSTR_VAL(target_buf) >= 2 && *(p - 2) == '\r' && *(p - 1) == '\n') {
648-
eol_len = 2;
649-
} else if (p == e && p > s) {
650-
const char *check = p - 1;
651-
while (check > s && *check == '\r') {
652-
check--;
653-
}
654-
if (check == s && *check == '\r') {
655-
s = p;
656-
continue;
657-
}
658-
eol_len = 1;
659-
}
644+
const char *c = s;
645+
while (c < p && (*c == '\n' || *c == '\r')) {
646+
c++;
660647
}
661-
662-
size_t line_len = p - s;
663-
if (line_len == eol_len) {
648+
if (c == p) {
664649
s = p;
665650
continue;
666651
}

ext/standard/tests/file/file_skip_empty_lines.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ var_dump($lines);
4343
file_put_contents($test_file, "\r\n");
4444
$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
4545
var_dump($lines);
46+
47+
file_put_contents($test_file, "\r\r\n\n");
48+
$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
49+
var_dump($lines);
50+
4651
?>
4752
--CLEAN--
4853
<?php unlink(__DIR__ . "/file_skip_empty_lines.tmp"); ?>
@@ -122,3 +127,5 @@ array(0) {
122127
}
123128
array(0) {
124129
}
130+
array(0) {
131+
}

0 commit comments

Comments
 (0)