mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.3'
* PHP-8.3: Fixed a bug in zend_memnistr with single character needle
This commit is contained in:
commit
25f42bc9ce
2 changed files with 34 additions and 1 deletions
33
Zend/tests/gh12457.phpt
Normal file
33
Zend/tests/gh12457.phpt
Normal file
|
@ -0,0 +1,33 @@
|
|||
--TEST--
|
||||
GH-12458 (Fix GH-12457: Fixed a bug in zend_memnistr)
|
||||
--FILE--
|
||||
<?php
|
||||
echo "Test case to ensure the issue is fixed.\n";
|
||||
var_dump(stripos('aaBBBBBb', 'b'));
|
||||
var_dump(stripos('aaBBBBBbb', 'b'));
|
||||
var_dump(stripos('aaBBBBBbbb', 'b'));
|
||||
var_dump(stristr('aaBBBBBb', 'b'));
|
||||
var_dump(stristr('aaBBBBBbb', 'b'));
|
||||
var_dump(stristr('aaBBBBBbbb', 'b'));
|
||||
|
||||
echo "\n";
|
||||
echo "Test cases to ensure the original functionality is not broken.\n";
|
||||
var_dump(stripos('aaBBBBBbc', 'c'));
|
||||
var_dump(stripos('aaBBBBBbC', 'c'));
|
||||
var_dump(stristr('aaBBBBBbc', 'c'));
|
||||
var_dump(stristr('aaBBBBBbC', 'c'));
|
||||
?>
|
||||
--EXPECTF--
|
||||
Test case to ensure the issue is fixed.
|
||||
int(2)
|
||||
int(2)
|
||||
int(2)
|
||||
string(6) "BBBBBb"
|
||||
string(7) "BBBBBbb"
|
||||
string(8) "BBBBBbbb"
|
||||
|
||||
Test cases to ensure the original functionality is not broken.
|
||||
int(8)
|
||||
int(8)
|
||||
string(1) "c"
|
||||
string(1) "C"
|
|
@ -937,7 +937,7 @@ zend_memnistr(const char *haystack, const char *needle, size_t needle_len, const
|
|||
const char *p_upper = NULL;
|
||||
if (first_lower != first_upper) {
|
||||
// If the needle length is 1 we don't need to look beyond p_lower as it is a guaranteed match
|
||||
size_t upper_search_length = end - (needle_len == 1 && p_lower != NULL ? p_lower : haystack);
|
||||
size_t upper_search_length = needle_len == 1 && p_lower != NULL ? p_lower - haystack : end - haystack;
|
||||
p_upper = (const char *)memchr(haystack, first_upper, upper_search_length);
|
||||
}
|
||||
const char *p = !p_upper || (p_lower && p_lower < p_upper) ? p_lower : p_upper;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue