php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77006 reaching the end of a intliterator makes it unusable
Submitted: 2018-10-12 06:59 UTC Modified: 2021-11-11 11:18 UTC
From: dontspamwespls at example dot org Assigned:
Status: Open Package: I18N and L10N related
PHP Version: 7.3.0RC3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
10 - 1 = ?
Subscribe to this entry?

 
 [2018-10-12 06:59 UTC] dontspamwespls at example dot org
Description:
------------
once valid() becomes false, previous() stops working

https://3v4l.org/A125P

Test script:
---------------
<?php

$iteratorx = IntlCodePointBreakIterator::createCodePointInstance();
$iteratorx->setText("abc");

$iterator = $iteratorx->getPartsIterator();
$iterator->rewind();
$iterator->next();
$iteratorx->previous(); // previous works
$iterator->next();
$iterator->next();
echo $iterator->current() . "\n"; // c... all fine

$iterator->next(); // no more code points, so it's invalid
var_dump($iterator->valid()); // false
var_dump($iterator->current()); // prints weird stuff... whatever...

$iteratorx->previous(); // cannot go back
var_dump($iterator->valid()); // broken
var_dump($iterator->current()); // broken

Expected result:
----------------
I expect valid() to be true after previous(), and current() set to the last code point


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-15 11:04 UTC] cmb@php.net
> var_dump($iterator->current()); // prints weird stuff... whatever...

That is because an IS_UNDEF value is returned.  Possible fix:


 ext/intl/common/common_enum.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ext/intl/common/common_enum.cpp b/ext/intl/common/common_enum.cpp
index adc7034d36..1e1b5ecb50 100644
--- a/ext/intl/common/common_enum.cpp
+++ b/ext/intl/common/common_enum.cpp
@@ -218,7 +218,7 @@ static PHP_METHOD(IntlIterator, current)
 
 	INTLITERATOR_METHOD_FETCH_OBJECT;
 	data = ii->iterator->funcs->get_current_data(ii->iterator);
-	if (data) {
+	if (data && Z_TYPE_P(data) != IS_UNDEF) {
 		ZVAL_COPY_DEREF(return_value, data);
 	}
 }
 [2021-11-11 11:18 UTC] nikic@php.net
-Package: intl +Package: I18N and L10N related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC