Skip to content

Commit b76677d

Browse files
committed
Disallow passing array as number to NumberFormatter::format()
Array to number conversion makes no sense here, and is likely to hide a programming error. Therefore we disallow passing an array in the first place.
1 parent 8a40689 commit b76677d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

ext/intl/formatter/formatter_format.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ PHP_FUNCTION( numfmt_format )
4444
{
4545
RETURN_THROWS();
4646
}
47+
if(Z_TYPE_P(number) == IS_ARRAY) {
48+
zend_type_error("given value must not be an array");
49+
RETURN_THROWS();
50+
}
4751

4852
/* Fetch the object. */
4953
FORMATTER_METHOD_FETCH_OBJECT;
5054

51-
if(Z_TYPE_P(number) != IS_ARRAY) {
52-
convert_scalar_to_number_ex(number);
53-
} else {
54-
convert_to_long(number);
55-
}
55+
convert_scalar_to_number_ex(number);
5656

5757
if(type == FORMAT_TYPE_DEFAULT) {
5858
switch(Z_TYPE_P(number)) {

ext/intl/tests/bug79212.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ var_dump($fmt->format([1], NumberFormatter::TYPE_INT64));
1515
?>
1616
--EXPECTF--
1717
string(21) "823749273428379%c%c%c%c%c%c"
18-
string(1) "1"
18+
19+
Fatal error: Uncaught TypeError: given value must not be an array in %s:%d
20+
Stack trace:
21+
#0 %s(%d): NumberFormatter->format(Array, 2)
22+
#1 {main}
23+
thrown in %s on line %d

0 commit comments

Comments
 (0)