Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/intl/breakiterator/breakiterator_iterators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter)
}

if (zoi_bit->key_type == PARTS_ITERATOR_KEY_LEFT) {
iter->index = cur;
iter->index = cur ? cur - 1 : cur; /* HACK: cater to increment in next(), but not rewind() */
} else if (zoi_bit->key_type == PARTS_ITERATOR_KEY_RIGHT) {
iter->index = next;
iter->index = cur ? next - 1 : next; /* HACK: cater to increment in next(), but not rewind() */
}
/* else zoi_bit->key_type == PARTS_ITERATOR_KEY_SEQUENTIAL
* No need to do anything, the engine increments ->index */
Expand Down
16 changes: 8 additions & 8 deletions ext/intl/tests/breakiter_getPartsIterator_var1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ array(5) {
array(5) {
[0]=>
string(3) "foo"
[4]=>
[3]=>
string(1) " "
[5]=>
[4]=>
string(3) "bar"
[8]=>
[7]=>
string(1) " "
[9]=>
[8]=>
string(3) "tao"
}
array(5) {
[3]=>
string(3) "foo"
[5]=>
[4]=>
string(1) " "
[8]=>
[7]=>
string(3) "bar"
[9]=>
[8]=>
string(1) " "
[12]=>
[11]=>
string(3) "tao"
}
==DONE==
34 changes: 34 additions & 0 deletions ext/intl/tests/bug78308.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Bug #78308 (IntlPartsIterator key is wrong for KEY_LEFT/KEY_RIGHT)
--SKIPIF--
<?php
if (!extension_loaded('intl')) die('skip intl extension not available');
?>
--FILE--
<?php
$iter = \IntlBreakIterator::createCodePointInstance();
$iter->setText('ABC');
echo "KEY_LEFT:\n";
foreach ($iter->getPartsIterator(\IntlPartsIterator::KEY_LEFT) as $key => $value) {
var_dump($key, $value);
}
echo "KEY_RIGHT:\n";
foreach ($iter->getPartsIterator(\IntlPartsIterator::KEY_RIGHT) as $key => $value) {
var_dump($key, $value);
}
?>
--EXPECT--
KEY_LEFT:
int(0)
string(1) "A"
int(1)
string(1) "B"
int(2)
string(1) "C"
KEY_RIGHT:
int(1)
string(1) "A"
int(2)
string(1) "B"
int(3)
string(1) "C"