Repository navigation
ext/intl: Fix grapheme_extract() next offset - #24160
Open
LamentXU123 wants to merge 1 commit into
Open
LamentXU123 wants to merge 1 commit into
LamentXU123 wants to merge 1 commit into
Conversation
devnexen
reviewed
Oct 6, 2026
|
|
||
| while ( !U8_IS_SINGLE(*pstr) && !U8_IS_LEAD(*pstr) ) { | ||
| pstr++; | ||
| start++; |
Member
There was a problem hiding this comment.
nit: your solution looks fine but would this work ?
--- a/ext/intl/grapheme/grapheme_string.c
+++ b/ext/intl/grapheme/grapheme_string.c
@@ -785,7 +785,8 @@ PHP_FUNCTION(grapheme_extract)
}
}
- str_len -= (pstr - str);
+ lstart = pstr - str;
+ str_len -= lstart;
/* if the string is all ASCII up to size+1 - or str_len whichever is first - then we are done.
(size + 1 because the size-th character might be the beginning of a grapheme cluster)
@@ -794,7 +795,7 @@ PHP_FUNCTION(grapheme_extract)
if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) {
size_t nsize = MIN(size, str_len);
if ( NULL != next ) {
- ZEND_TRY_ASSIGN_REF_LONG(next, start + nsize);
+ ZEND_TRY_ASSIGN_REF_LONG(next, lstart + nsize);
}
RETURN_STRINGL(pstr, nsize);
}
@@ -828,7 +829,7 @@ PHP_FUNCTION(grapheme_extract)
ubrk_close(bi);
if ( NULL != next ) {
- ZEND_TRY_ASSIGN_REF_LONG(next, start + ret_pos);
+ ZEND_TRY_ASSIGN_REF_LONG(next, lstart + ret_pos);
}
RETURN_STRINGL(((char *)pstr), ret_pos);When the starting position lies inside a multibyte UTF-8 character, grapheme_extract() advances the cursor but reports a next offset based on the original position. Derive the adjusted offset from the cursor for both extraction paths. Add regression coverage for extraction modes, ASCII and Unicode tails, and negative starting offsets, and document the fix in NEWS. Co-authored-by: David Carlier <devnexen@gmail.com>
devnexen
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Next should be 3 instead.