Skip to content

Commit 5f842ce

Browse files
committed
feedback
1 parent 4a4244f commit 5f842ce

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

ext/intl/collator/collator_convert.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,8 @@ static void collator_set_conversion_error(UErrorCode status, const char *message
4444
status = U_MEMORY_ALLOCATION_ERROR;
4545
}
4646

47-
if (INTL_G(current_collator_error)) {
48-
intl_error_set(INTL_G(current_collator_error), status, message);
49-
} else {
50-
intl_error_set(nullptr, status, message);
51-
}
47+
ZEND_ASSERT(INTL_G(current_collator_error) != nullptr);
48+
intl_error_set(INTL_G(current_collator_error), status, message);
5249
}
5350

5451
/* {{{ collator_convert_hash_item_from_utf8_to_utf16 */
@@ -241,6 +238,7 @@ U_CFUNC zval* collator_convert_object_to_string( zval* obj, zval *rv )
241238
if( U_FAILURE( status ) ) {
242239
collator_set_conversion_error(status, "Error converting object string from UTF-8 to UTF-16");
243240
zval_ptr_dtor( zstr );
241+
ZVAL_NULL( zstr );
244242
return nullptr;
245243
}
246244

ext/intl/collator/collator_sort.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2)
6363

6464
ZVAL_NULL(&str1);
6565
str1_p = collator_convert_object_to_string( op1, &str1 );
66-
if( str1_p == nullptr )
66+
if( str1_p == nullptr ) {
6767
return FAILURE;
68+
}
6869

6970
ZVAL_NULL(&str2);
7071
str2_p = collator_convert_object_to_string( op2, &str2 );
@@ -202,8 +203,9 @@ static int collator_icu_compare_function(zval *result, zval *op1, zval *op2)
202203
{
203204
int rc = SUCCESS;
204205
zend_string *str1 = collator_zval_to_string(op1);
205-
if( str1 == nullptr )
206+
if( str1 == nullptr ) {
206207
return FAILURE;
208+
}
207209

208210
zend_string *str2 = collator_zval_to_string(op2);
209211
if( str2 == nullptr ) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Collator::sort() reports conversion errors in SORT_REGULAR comparisons
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
class BadRegularString {
8+
public function __toString(): string {
9+
return "\xFF";
10+
}
11+
}
12+
13+
$coll = new Collator('en_US');
14+
$array = [new BadRegularString(), 1];
15+
16+
var_dump($coll->sort($array, Collator::SORT_REGULAR));
17+
var_dump($array[0] instanceof BadRegularString);
18+
var_dump($array[1]);
19+
var_dump(intl_get_error_code() === U_INVALID_CHAR_FOUND);
20+
echo intl_get_error_message(), "\n";
21+
var_dump($coll->getErrorCode() === U_INVALID_CHAR_FOUND);
22+
echo $coll->getErrorMessage(), "\n";
23+
?>
24+
--EXPECT--
25+
bool(false)
26+
bool(true)
27+
int(1)
28+
bool(true)
29+
Collator::sort(): Error comparing array values: U_INVALID_CHAR_FOUND
30+
bool(true)
31+
Collator::sort(): Error comparing array values: U_INVALID_CHAR_FOUND

0 commit comments

Comments
 (0)