Skip to content

Commit 42cc4ad

Browse files
authored
ext/intl: Fix ResourceBundle fallback-disabled error message (#22236)
Fix the typo in ResourceBundle fallback-disabled error message
1 parent 0d2d353 commit 42cc4ad

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

NEWS

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

6767
- Intl:
68+
. Fixed malformed ResourceBundle::get() error message when fallback is
69+
disabled. (Weilin Du)
6870
. Added IntlNumberRangeFormatter class to format an interval of two numbers
6971
with a given skeleton, locale, collapse type and identity fallback.
7072
(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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
require_once "resourcebundle.inc";
8+
9+
$fixture = __DIR__ . '/resourcebundle_get_without_fallback_tmp';
10+
if (!is_dir($fixture)) {
11+
mkdir($fixture);
12+
}
13+
copy(BUNDLE . '/root.res', $fixture . '/root.res');
14+
15+
$resIndex = file_get_contents(BUNDLE . '/res_index.res');
16+
$resIndex = str_replace("\0es\0root", "\0en\0root", $resIndex, $replacementCount);
17+
if ($replacementCount !== 1) {
18+
die("Failed to prepare resource bundle index\n");
19+
}
20+
file_put_contents($fixture . '/res_index.res', $resIndex);
21+
22+
// Keep the binary layout intact while making this key fall back to root.res.
23+
$enBundle = file_get_contents(BUNDLE . '/es.res');
24+
$enBundle = str_replace('teststring', 'teststrinh', $enBundle, $replacementCount);
25+
if ($replacementCount !== 1) {
26+
die("Failed to prepare resource bundle fixture\n");
27+
}
28+
file_put_contents($fixture . '/en.res', $enBundle);
29+
30+
$bundle = new ResourceBundle('en', $fixture);
31+
echo debug($bundle->get('teststring', false));
32+
33+
$bundle = resourcebundle_create('en', $fixture);
34+
echo debug(resourcebundle_get($bundle, 'teststring', false));
35+
?>
36+
--EXPECTF--
37+
NULL
38+
%i: ResourceBundle::get(): Cannot load element 'teststring' without fallback to %s: U_USING_%s_WARNING
39+
NULL
40+
%i: resourcebundle_get(): Cannot load element 'teststring' without fallback to %s: U_USING_%s_WARNING
41+
--CLEAN--
42+
<?php
43+
$fixture = __DIR__ . '/resourcebundle_get_without_fallback_tmp';
44+
@unlink($fixture . '/en.res');
45+
@unlink($fixture . '/root.res');
46+
@unlink($fixture . '/res_index.res');
47+
@rmdir($fixture);
48+
?>

0 commit comments

Comments
 (0)