-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntlPartsIterator key is wrong for KEY_LEFT/KEY_RIGHT #7734
Comments
Apparently the first example is resolved now on master. https://3v4l.org/O8374/rfc#vgit.master |
The second case is also fixed, except that there's a different issue where Line 4513 in e1a2383
Usually the index is computed in diff --git a/ext/intl/breakiterator/breakiterator_iterators.cpp b/ext/intl/breakiterator/breakiterator_iterators.cpp
index 2027fb45c5..3ea56e80d3 100644
--- a/ext/intl/breakiterator/breakiterator_iterators.cpp
+++ b/ext/intl/breakiterator/breakiterator_iterators.cpp
@@ -127,6 +127,7 @@ typedef struct zoi_break_iter_parts {
zoi_with_current zoi_cur;
parts_iter_key_type key_type;
BreakIterator_object *bio; /* so we don't have to fetch it all the time */
+ zend_ulong index_right;
} zoi_break_iter_parts;
static void _breakiterator_parts_destroy_it(zend_object_iterator *iter)
@@ -136,8 +137,13 @@ static void _breakiterator_parts_destroy_it(zend_object_iterator *iter)
static void _breakiterator_parts_get_current_key(zend_object_iterator *iter, zval *key)
{
- /* the actual work is done in move_forward and rewind */
- ZVAL_LONG(key, iter->index);
+ zoi_break_iter_parts *zoi_bit = (zoi_break_iter_parts*)iter;
+
+ if (iter->index == 0 && zoi_bit->key_type == PARTS_ITERATOR_KEY_RIGHT) {
+ ZVAL_LONG(key, zoi_bit->index_right);
+ } else {
+ ZVAL_LONG(key, iter->index);
+ }
}
static void _breakiterator_parts_move_forward(zend_object_iterator *iter)
@@ -163,6 +169,7 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter)
iter->index = cur;
} else if (zoi_bit->key_type == PARTS_ITERATOR_KEY_RIGHT) {
iter->index = next;
+ zoi_bit->index_right = next;
}
/* else zoi_bit->key_type == PARTS_ITERATOR_KEY_SEQUENTIAL
* No need to do anything, the engine increments ->index */
@@ -229,6 +236,7 @@ void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv,
assert(((zoi_break_iter_parts*)ii->iterator)->bio->biter != NULL);
((zoi_break_iter_parts*)ii->iterator)->key_type = key_type;
+ ((zoi_break_iter_parts*)ii->iterator)->index_right = 0;
}
U_CFUNC PHP_METHOD(IntlPartsIterator, getBreakIterator) But that's not very clean either. I don't see any other ways to solve this. Fun fact, |
Feel free to close this and spin off a new bug with the rewind behavior, if you think that would be better. I'm curious to know what fixed this on master as it sounds like it was unintentionally fixed. |
I did some more digging, the reason this works on master is because we changed how PHP-8.1: php-src/Zend/zend_interfaces.c Lines 337 to 342 in 925a309
master: php-src/Zend/zend_interfaces.c Lines 352 to 362 in 51f750e
|
Description
When creating an
IntlPartsIterator
with a type ofIntlPartsIterator::KEY_LEFT
orIntlPartsIterator::KEY_RIGHT
, the returned key value is off by one after the first key. So for the string "ABC" you would get 0, 2, 3, instead of the expected 0, 1, 2.https://3v4l.org/O8374
https://3v4l.org/SNUAX
Originally filed as https://bugs.php.net/bug.php?id=78308
Initial fix attempt #4446
PHP Version
8.1.0
Operating System
No response
The text was updated successfully, but these errors were encountered: