mirror of
https://github.com/php/php-src.git
synced 2024-11-28 04:14:26 +08:00
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #74264: grapheme_strrpos() broken for negative offsets
This commit is contained in:
commit
8071bd2faf
1
NEWS
1
NEWS
@ -20,6 +20,7 @@ PHP NEWS
|
|||||||
. Fixed bug #72809 (Locale::lookup() wrong result with canonicalize option).
|
. Fixed bug #72809 (Locale::lookup() wrong result with canonicalize option).
|
||||||
(cmb)
|
(cmb)
|
||||||
. Fixed bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone). (cmb)
|
. Fixed bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone). (cmb)
|
||||||
|
. Fixed bug #74264 (grapheme_strrpos() broken for negative offsets). (cmb)
|
||||||
|
|
||||||
- OpenSSL:
|
- OpenSSL:
|
||||||
. Fixed bug #52093 (openssl_csr_sign truncates $serial). (cmb)
|
. Fixed bug #52093 (openssl_csr_sign truncates $serial). (cmb)
|
||||||
|
@ -157,16 +157,29 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle,
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
status = U_ZERO_ERROR;
|
status = U_ZERO_ERROR;
|
||||||
usearch_setOffset(src, offset_pos, &status);
|
usearch_setOffset(src, last ? 0 : offset_pos, &status);
|
||||||
STRPOS_CHECK_STATUS(status, "Invalid search offset");
|
STRPOS_CHECK_STATUS(status, "Invalid search offset");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(last) {
|
if(last) {
|
||||||
char_pos = usearch_last(src, &status);
|
if (offset >= 0) {
|
||||||
if(char_pos < offset_pos) {
|
char_pos = usearch_last(src, &status);
|
||||||
/* last one is beyound our start offset */
|
if(char_pos < offset_pos) {
|
||||||
char_pos = USEARCH_DONE;
|
/* last one is beyond our start offset */
|
||||||
|
char_pos = USEARCH_DONE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* searching backwards is broken, so we search forwards, albeit it's less efficient */
|
||||||
|
int32_t prev_pos = USEARCH_DONE;
|
||||||
|
do {
|
||||||
|
char_pos = usearch_next(src, &status);
|
||||||
|
if (char_pos == USEARCH_DONE || char_pos > offset_pos) {
|
||||||
|
char_pos = prev_pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev_pos = char_pos;
|
||||||
|
} while(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char_pos = usearch_next(src, &status);
|
char_pos = usearch_next(src, &status);
|
||||||
|
26
ext/intl/tests/bug74264.phpt
Normal file
26
ext/intl/tests/bug74264.phpt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
--TEST--
|
||||||
|
Bug #74264 (grapheme_sttrpos() broken for negative offsets)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
if (!extension_loaded('intl')) die("skip intl extension not available");
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
foreach (range(-5, -1) as $offset) {
|
||||||
|
var_dump(
|
||||||
|
grapheme_strrpos('déjàààà', 'à', $offset),
|
||||||
|
grapheme_strripos('DÉJÀÀÀÀ', 'à', $offset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
bool(false)
|
||||||
|
int(3)
|
||||||
|
int(3)
|
||||||
|
int(4)
|
||||||
|
int(4)
|
||||||
|
int(5)
|
||||||
|
int(5)
|
||||||
|
int(6)
|
||||||
|
int(6)
|
Loading…
Reference in New Issue
Block a user