Skip to content

Commit a80db7b

Browse files
committed
Fix GH-12282: IntlDateFormatter::construct should throw an exception is the locale field has an invalid value.
Close GH-12282
1 parent 4f044e9 commit a80db7b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818
- Intl:
1919
. Fixed bug GH-12243 (segfault on IntlDateFormatter::construct).
2020
(David Carlier)
21+
. Fixed bug GH-12282 (IntlDateFormatter::construct should throw an exception
22+
on an invalid locale). (David Carlier)
2123

2224
- PCRE:
2325
. Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with

ext/intl/dateformat/dateformat_create.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin
111111
locale_str = (char *) intl_locale_get_default();
112112
}
113113
locale = Locale::createFromName(locale_str);
114+
/* get*Name accessors being set does not preclude being bogus */
115+
if (locale.isBogus() || strlen(locale.getISO3Language()) == 0) {
116+
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid locale", 0);
117+
return FAILURE;
118+
}
114119

115120
/* process calendar */
116121
if (datefmt_process_calendar_arg(calendar_obj, calendar_long, calendar_is_null, locale, "datefmt_create",

ext/intl/tests/gh12282.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GitHub #12282 IntlDateFormatter::locale with invalid value.
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
try {
9+
new IntlDateFormatter(
10+
'xx',
11+
IntlDateFormatter::FULL,
12+
IntlDateFormatter::FULL,
13+
null,
14+
null,
15+
'w'
16+
);
17+
} catch (\IntlException $e) {
18+
echo $e->getMessage();
19+
}
20+
--EXPECT--
21+
datefmt_create: invalid locale: U_ILLEGAL_ARGUMENT_ERROR

0 commit comments

Comments
 (0)