Skip to content

Commit cd55746

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/intl: fix IntlListFormatter object error state after format() failures
2 parents e22ba55 + 946d687 commit cd55746

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

ext/intl/listformatter/listformatter_class.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ PHP_METHOD(IntlListFormatter, format)
131131
Z_PARAM_ARRAY_HT(ht)
132132
ZEND_PARSE_PARAMETERS_END();
133133

134+
intl_errors_reset(LISTFORMATTER_ERROR_P(obj));
135+
134136
uint32_t count = zend_hash_num_elements(ht);
135137
if (count == 0) {
136138
RETURN_EMPTY_STRING();
@@ -152,7 +154,7 @@ PHP_METHOD(IntlListFormatter, format)
152154
zend_tmp_string_release(tmp_str);
153155

154156
if (U_FAILURE(conv_status)) {
155-
intl_error_set(nullptr, conv_status, "Failed to convert string to UTF-16");
157+
intl_errors_set(LISTFORMATTER_ERROR_P(obj), conv_status, "Failed to convert string to UTF-16");
156158
RETURN_FALSE;
157159
}
158160

@@ -165,14 +167,14 @@ PHP_METHOD(IntlListFormatter, format)
165167
LISTFORMATTER_OBJECT(obj)->format(items.get(), count, result, status);
166168

167169
if (U_FAILURE(status)) {
168-
intl_error_set(nullptr, status, "Failed to format list");
170+
intl_errors_set(LISTFORMATTER_ERROR_P(obj), status, "Failed to format list");
169171
RETURN_FALSE;
170172
}
171173

172174
zend_string *ret = intl_charFromString(result, &status);
173175

174176
if (!ret) {
175-
intl_error_set(nullptr, status, "Failed to convert result to UTF-8");
177+
intl_errors_set(LISTFORMATTER_ERROR_P(obj), status, "Failed to convert result to UTF-8");
176178
RETURN_FALSE;
177179
}
178180

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
IntlListFormatter getErrorCode()/getErrorMessage() reflect format() failures
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$formatter = new IntlListFormatter('en_US');
9+
10+
var_dump($formatter->format(["\x80"]));
11+
var_dump($formatter->getErrorCode() === U_INVALID_CHAR_FOUND);
12+
var_dump($formatter->getErrorMessage());
13+
14+
var_dump($formatter->format(['a', 'b']));
15+
var_dump($formatter->getErrorCode() === U_ZERO_ERROR);
16+
var_dump($formatter->getErrorMessage());
17+
18+
?>
19+
--EXPECT--
20+
bool(false)
21+
bool(true)
22+
string(85) "IntlListFormatter::format(): Failed to convert string to UTF-16: U_INVALID_CHAR_FOUND"
23+
string(7) "a and b"
24+
bool(true)
25+
string(12) "U_ZERO_ERROR"

0 commit comments

Comments
 (0)