diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 5c96f41fadf35..dbc2273f32970 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -113,7 +113,8 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin locale = Locale::createFromName(locale_str); /* get*Name accessors being set does not preclude being bogus */ if (locale.isBogus() || strlen(locale.getISO3Language()) == 0) { - goto error; + zend_argument_value_error(1, "\"%s\" is invalid", locale_str); + return FAILURE; } /* process calendar */ diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index ed1806d6bbc55..53c5a3e9be2ab 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -17,6 +17,7 @@ #endif #include +#include #include "php_intl.h" #include "formatter_class.h" @@ -63,6 +64,11 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_ locale = intl_locale_get_default(); } + if (strlen(uloc_getISO3Language(locale)) == 0) { + zend_argument_value_error(1, "\"%s\" is invalid", locale); + return FAILURE; + } + /* Create an ICU number formatter. */ FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt index 2a2908e908c74..c9c621c6b7626 100644 --- a/ext/intl/tests/formatter_fail.phpt +++ b/ext/intl/tests/formatter_fail.phpt @@ -119,10 +119,14 @@ Deprecated: numfmt_create(): Passing null to parameter #1 ($locale) of type stri Deprecated: numfmt_create(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d -IntlException: Constructor failed in %s on line %d -'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' +ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "%s" is invalid in %s on line %d +'U_ZERO_ERROR' + +ValueError: NumberFormatter::create(): Argument #1 ($locale) "%s" is invalid in %s on line %d +'U_ZERO_ERROR' + +ValueError: numfmt_create(): Argument #1 ($locale) "%s" is invalid in %s on line %d +'U_ZERO_ERROR' TypeError: NumberFormatter::__construct(): Argument #1 ($locale) must be of type string, array given in %s on line %d 'U_ZERO_ERROR' diff --git a/ext/intl/tests/gh12282.phpt b/ext/intl/tests/gh12282.phpt index a30899a08c7d0..b12dc655f7051 100644 --- a/ext/intl/tests/gh12282.phpt +++ b/ext/intl/tests/gh12282.phpt @@ -5,18 +5,25 @@ intl --FILE-- getMessage() . PHP_EOL; } -object(IntlDateFormatter)#1 (0) { + +Locale::setDefault('xx'); +try { + new IntlDateFormatter(Locale::getDefault()); +} catch (\ValueError $e) { + echo $e->getMessage(); } +--EXPECT-- +IntlDateFormatter::__construct(): Argument #1 ($locale) "xx" is invalid +IntlDateFormatter::__construct(): Argument #1 ($locale) "xx" is invalid diff --git a/ext/intl/tests/gh12727.phpt b/ext/intl/tests/gh12727.phpt new file mode 100644 index 0000000000000..e04b5eb26a125 --- /dev/null +++ b/ext/intl/tests/gh12727.phpt @@ -0,0 +1,15 @@ +--TEST-- +numfmt creation failures +--EXTENSIONS-- +intl +--FILE-- +getMessage(); +} +?> +--EXPECTF-- +NumberFormatter::__construct(): Argument #1 ($locale) "%s" is invalid