Skip to content

Commit 43cb254

Browse files
committed
Flush filter during non-strict encoding detection
If we reach the end of the string without reducing to a single encoding, then we should flush to check whether the last character is incomplete.
1 parent 1ce81b6 commit 43cb254

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,9 @@ int mbfl_encoding_detector_feed(mbfl_encoding_detector *identd, mbfl_string *str
362362
p++;
363363
}
364364

365-
if (identd->strict) {
366-
for (int i = 0; i < num; i++) {
367-
mbfl_convert_filter *filter = identd->filter_list[i];
368-
(filter->filter_flush)(filter);
369-
}
365+
for (int i = 0; i < num; i++) {
366+
mbfl_convert_filter *filter = identd->filter_list[i];
367+
(filter->filter_flush)(filter);
370368
}
371369

372370
return 0;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
mb_detect_encoding() with incomplete trailing sequence
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
8+
// Even in non-strict mode, this should detect as ISO-8859-1. When the end of the string is
9+
// reached neither have illegal characters and would be picked based on score. However, flushing
10+
// the string will disqualify UTF-8 due to illegal characters.
11+
var_dump(mb_detect_encoding("A\xC2", ["UTF-8", "ISO-8859-1"]));
12+
13+
?>
14+
--EXPECT--
15+
string(10) "ISO-8859-1"

0 commit comments

Comments
 (0)