Skip to content

Commit 369ec87

Browse files
Address latest comment
1 parent 47ddc27 commit 369ec87

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ PHP NEWS
140140
. Fixed bug GH-13204 (glob() fails if square bracket is in current directory).
141141
(ndossche)
142142
. Add array size maximum to array_diff(). (ndossche)
143+
. Fixed bug GH-18120 (Honor FILE_SKIP_EMPTY_LINES even when
144+
FILE_IGNORE_NEW_LINES is not set). (alexandre-daubois)
143145

144146
- Streams:
145147
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream

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)