Skip to content
Merged
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 @@ -42,6 +42,8 @@ PHP NEWS
string. (Weilin Du)
. Fixed IntlListFormatter::__construct() leaving stale global error state
after successful calls. (Weilin Du)
. Fixed IntlNumberRangeFormatter leaving stale global error state after
successful createFromSkeleton() and format() calls. (Weilin Du)
. Implemented GH-20255 (Add a predefined calendar constant in
IntlDateFormatter for the proleptic gregorian calendar). (David Carlier)
. Added SpoofChecker::areBidiConfusable(). (David Carlier)
Expand Down
9 changes: 7 additions & 2 deletions ext/intl/rangeformatter/rangeformatter_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, createFromSkeleton)
zend_long collapse;
zend_long identityFallback;

intl_error_reset(NULL);

ZEND_PARSE_PARAMETERS_START(4,4)
Z_PARAM_STRING(skeleton, skeleton_len)
Z_PARAM_STRING(locale, locale_len)
Expand Down Expand Up @@ -158,7 +160,10 @@ U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, format)
zval *start;
zval *end;

intl_error_reset(NULL);

IntlNumberRangeFormatter_object* obj = Z_INTL_RANGEFORMATTER_P(ZEND_THIS);
intl_error_reset(RANGEFORMATTER_ERROR_P(obj));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reset is a no-op: every failure path calls intl_error_set(NULL, ...),
which only writes the global error, so the object slot is never set.
Switch the two calls in format() to
intl_errors_set(RANGEFORMATTER_ERROR_P(obj), ...), then getErrorCode()
stops always returning U_ZERO_ERROR.


ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_NUMBER(start)
Expand All @@ -179,13 +184,13 @@ U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, format)
INTL_G(error_level) = 0;

if (U_FAILURE(error)) {
intl_error_set(NULL, error, "Failed to format number range");
intl_errors_set(RANGEFORMATTER_ERROR_P(obj), error, "Failed to format number range");
}

zend_string *ret = intl_charFromString(result, &error);

if (U_FAILURE(error)) {
intl_error_set(NULL, error, "Failed to convert result to UTF-8");
intl_errors_set(RANGEFORMATTER_ERROR_P(obj), error, "Failed to convert result to UTF-8");
}

INTL_G(use_exceptions) = old_use_exception;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--TEST--
IntlNumberRangeFormatter resets stale errors
--EXTENSIONS--
intl
--SKIPIF--
<?php
if (version_compare(INTL_ICU_VERSION, '63.0') < 0) {
die('skip for ICU < 63.0');
}
?>
--FILE--
<?php
try {
IntlNumberRangeFormatter::createFromSkeleton(
'invalid skeleton here',
'en_US',
IntlNumberRangeFormatter::COLLAPSE_AUTO,
IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE
);
} catch (IntlException $exception) {
var_dump(str_contains(intl_get_error_message(), 'U_NUMBER_SKELETON_SYNTAX_ERROR'));
}

$formatter = IntlNumberRangeFormatter::createFromSkeleton(
'',
'en_US',
IntlNumberRangeFormatter::COLLAPSE_AUTO,
IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE
);

var_dump(intl_get_error_code());
var_dump(intl_get_error_message());

try {
IntlNumberRangeFormatter::createFromSkeleton(
'invalid skeleton here',
'en_US',
IntlNumberRangeFormatter::COLLAPSE_AUTO,
IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE
);
} catch (IntlException $exception) {
}

$formatter->format(1, 2);

var_dump(intl_get_error_code());
var_dump(intl_get_error_message());
?>
--EXPECT--
bool(true)
int(0)
string(12) "U_ZERO_ERROR"
int(0)
string(12) "U_ZERO_ERROR"
Loading