Merge branch 'PHP-8.0'

* PHP-8.0:
  Fix #74264: grapheme_strrpos() broken for negative offsets
This commit is contained in:
Christoph M. Becker 2021-07-05 18:18:44 +02:00
commit 097cae9d90
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
2 changed files with 42 additions and 5 deletions

View file

@ -157,17 +157,30 @@ int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle,
goto finish;
}
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");
}
if(last) {
if (offset >= 0) {
char_pos = usearch_last(src, &status);
if(char_pos < offset_pos) {
/* last one is beyound our start offset */
/* 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 {
char_pos = usearch_next(src, &status);
}

View file

@ -0,0 +1,24 @@
--TEST--
Bug #74264 (grapheme_sttrpos() broken for negative offsets)
--EXTENSIONS--
intl
--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)