Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ PHP NEWS
when pos.size < 2). (Oblivionsage)

- Intl:
. Fixed IntlListFormatter::getErrorCode() and getErrorMessage() not
reflecting format() failures. (Weilin Du)
. Fix leak in umsg_format_helper(). (ndossche)

- LDAP:
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ PHP 8.5 UPGRADE NOTES
indicates more accurately which call site caused what error.
Moreover, some ext/date exceptions have been wrapped inside a
IntlException now.
. IntlListFormatter::getErrorCode() and getErrorMessage() now reflect
IntlListFormatter::format() failures.

- Lexbor:
. An always enabled lexbor extension is added. It contains the lexbor
Expand Down
10 changes: 6 additions & 4 deletions ext/intl/listformatter/listformatter_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ PHP_METHOD(IntlListFormatter, format)
Z_PARAM_ARRAY_HT(ht)
ZEND_PARSE_PARAMETERS_END();

intl_errors_reset(LISTFORMATTER_ERROR_P(obj));

uint32_t count = zend_hash_num_elements(ht);
if (count == 0) {
RETURN_EMPTY_STRING();
Expand Down Expand Up @@ -154,7 +156,7 @@ PHP_METHOD(IntlListFormatter, format)
}
efree(items);
efree(itemLengths);
intl_error_set(NULL, status, "Failed to convert string to UTF-16");
intl_errors_set(LISTFORMATTER_ERROR_P(obj), status, "Failed to convert string to UTF-16");
RETURN_FALSE;
}

Expand All @@ -170,7 +172,7 @@ PHP_METHOD(IntlListFormatter, format)
resultLength = ulistfmt_format(LISTFORMATTER_OBJECT(obj), items, itemLengths, count, NULL, 0, &status);

if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) {
intl_error_set(NULL, status, "Failed to format list");
intl_errors_set(LISTFORMATTER_ERROR_P(obj), status, "Failed to format list");
RETVAL_FALSE;
goto cleanup;
}
Expand All @@ -184,7 +186,7 @@ PHP_METHOD(IntlListFormatter, format)
if (result) {
efree(result);
}
intl_error_set(NULL, status, "Failed to format list");
intl_errors_set(LISTFORMATTER_ERROR_P(obj), status, "Failed to format list");
RETVAL_FALSE;
goto cleanup;
}
Expand All @@ -194,7 +196,7 @@ PHP_METHOD(IntlListFormatter, format)
efree(result);

if (!ret) {
intl_error_set(NULL, status, "Failed to convert result to UTF-8");
intl_errors_set(LISTFORMATTER_ERROR_P(obj), status, "Failed to convert result to UTF-8");
RETVAL_FALSE;
} else {
RETVAL_NEW_STR(ret);
Expand Down
25 changes: 25 additions & 0 deletions ext/intl/tests/listformatter/listformatter_get_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
IntlListFormatter getErrorCode()/getErrorMessage() reflect format() failures
--EXTENSIONS--
intl
--FILE--
<?php

$formatter = new IntlListFormatter('en_US');

var_dump($formatter->format(["\x80"]));
var_dump($formatter->getErrorCode() === U_INVALID_CHAR_FOUND);
var_dump($formatter->getErrorMessage());

var_dump($formatter->format(['a', 'b']));
var_dump($formatter->getErrorCode() === U_ZERO_ERROR);
var_dump($formatter->getErrorMessage());

?>
--EXPECT--
bool(false)
bool(true)
string(85) "IntlListFormatter::format(): Failed to convert string to UTF-16: U_INVALID_CHAR_FOUND"
string(7) "a and b"
bool(true)
string(12) "U_ZERO_ERROR"