]> granicus.if.org Git - php/commitdiff
Prevent double-construction of NumberFormatter
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Aug 2020 08:16:32 +0000 (10:16 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Aug 2020 08:25:09 +0000 (10:25 +0200)
ext/intl/formatter/formatter_main.c
ext/intl/tests/formatter_fail.phpt

index 80d99b3f011416a0f5419b1a8cb3938cb7c88b74..8f44f33fa369c6ba2a02a33e91f531f4e3ef3e6e 100644 (file)
@@ -43,6 +43,10 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
        INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
        object = return_value;
        FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
+       if (FORMATTER_OBJECT(nfo)) {
+               zend_throw_error(NULL, "NumberFormatter object is already constructed");
+               return FAILURE;
+       }
 
        /* Convert pattern (if specified) to UTF-16. */
        if(pattern && pattern_len) {
index 3201c9a82b1081f2f1f10b63633662e5565cca78..15981178ac5b5bd10ec5ad077b0a97ccf9a6d230 100644 (file)
@@ -75,6 +75,15 @@ try {
 }
 err($fmt);
 
+$fmt = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
+try {
+    $fmt->__construct('en_US', NumberFormatter::DECIMAL);
+} catch (Error $e) {
+    print_exception($e);
+    $fmt = null;
+}
+err($fmt);
+
 foreach($args as $arg) {
     $fmt = crt("O", $arg[0], $arg[1]);
     err($fmt);
@@ -95,6 +104,9 @@ ArgumentCountError: numfmt_create() expects at least 2 parameters, 0 given in %s
 ArgumentCountError: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d
 'U_ZERO_ERROR'
 
+Error: NumberFormatter object is already constructed in %s on line %d
+'U_ZERO_ERROR'
+
 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'