Skip to content

Commit 58334a4

Browse files
committed
Check for empty string
1 parent 81eadeb commit 58334a4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ext/intl/resourcebundle/resourcebundle_class.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ static zval *resource_bundle_array_fetch(
183183
intl_error_reset(INTL_DATA_ERROR_P(rb));
184184

185185
if (offset_str) {
186-
// TODO Check is not empty?
186+
if (UNEXPECTED(ZSTR_LEN(offset_str) == 0)) {
187+
if (offset_arg_num) {
188+
zend_argument_value_error(offset_arg_num, "cannot be empty");
189+
} else {
190+
zend_value_error("Offset cannot be empty");
191+
}
192+
return NULL;
193+
}
187194
key = ZSTR_VAL(offset_str);
188195
rb->child = ures_getByKey(rb->me, key, rb->child, &INTL_DATA_ERROR_CODE(rb) );
189196
} else {

ext/intl/tests/resourcebundle_dimension_errors.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ try {
3434
} catch (\Throwable $e) {
3535
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
3636
}
37+
try {
38+
var_dump($r['']);
39+
} catch (\Throwable $e) {
40+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
41+
}
3742
try {
3843
/* This can only happen on 64bit */
3944
if (PHP_INT_SIZE > 4) {
@@ -52,4 +57,5 @@ Error: Cannot use object of type ResourceBundle as array
5257
string(7) "default"
5358
TypeError: Cannot access offset of type float on ResourceBundle
5459
TypeError: Cannot access offset of type stdClass on ResourceBundle
60+
ValueError: Offset cannot be empty
5561
ValueError: Index must be between -2147483648 and 2147483647

0 commit comments

Comments
 (0)