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-06-15 11:04 UTC
From: dontspamwespls at example dot org Assigned:
Status: Open Package: intl (PECL)
PHP Version: 7.3.0RC3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dontspamwespls at example dot org
New email:
PHP Version: OS:

 

 [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);
 	}
 }
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jul 25 10:01:23 2021 UTC