Skip to content

Commit fdee518

Browse files
committed
ext/intl: Fix ResourceBundle fallback-disabled error message
1 parent 95b5b48 commit fdee518

4 files changed

Lines changed: 27 additions & 3 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ PHP NEWS
6161
. Upgrade xxHash to 0.8.2. (timwolla)
6262

6363
- Intl:
64+
. Fixed malformed ResourceBundle::get() error message when fallback is
65+
disabled. (Weilin Du)
6466
. Added IntlNumberRangeFormatter class to format an interval of two numbers
6567
with a given skeleton, locale, collapse type and identity fallback.
6668
(BogdanUngureanu)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ PHP 8.6 UPGRADE NOTES
4747
. UConverter::transcode() now rejects from_subst and to_subst option values
4848
longer than 127 bytes instead of silently truncating the length before
4949
passing it to ICU.
50+
. ResourceBundle::get() and resourcebundle_get() now report fallback-disabled
51+
resource lookups with "without fallback to <locale>" instead of the
52+
malformed "without fallback from to <locale>".
5053

5154
- PCNTL:
5255
. pcntl_alarm() now raises a ValueError if the seconds argument is

ext/intl/resourcebundle/resourcebundle_class.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ static zval *resource_bundle_array_fetch(
220220
}
221221

222222
if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
223-
UErrorCode icuerror;
223+
UErrorCode icuerror = U_ZERO_ERROR;
224224
const char * locale = ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &icuerror );
225225
if (is_numeric) {
226-
spprintf(&pbuf, 0, "Cannot load element %d without fallback from to %s", index, locale);
226+
spprintf(&pbuf, 0, "Cannot load element %d without fallback to %s", index, locale);
227227
} else {
228-
spprintf(&pbuf, 0, "Cannot load element '%s' without fallback from to %s", key, locale);
228+
spprintf(&pbuf, 0, "Cannot load element '%s' without fallback to %s", key, locale);
229229
}
230230
intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf);
231231
efree(pbuf);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
ResourceBundle::get() rejects fallback results when fallback is disabled with correct error message
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
include "resourcebundle.inc";
8+
9+
$bundle = new ResourceBundle('es', BUNDLE);
10+
echo debug($bundle->get('testint', false));
11+
12+
$bundle = resourcebundle_create('es', BUNDLE);
13+
echo debug(resourcebundle_get($bundle, 'testint', false));
14+
?>
15+
--EXPECTF--
16+
NULL
17+
%i: Cannot load element 'testint' without fallback to %s: U_USING_%s_WARNING
18+
NULL
19+
%i: Cannot load element 'testint' without fallback to %s: U_USING_%s_WARNING

0 commit comments

Comments
 (0)