diff --git a/NEWS b/NEWS index 823e8ad40d4..57f53180268 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,10 @@ PHP NEWS . Fixed GH-12077 (PHP 8.3.0RC1 borked socket-close-on-exec.phpt). (Jakub Zelenka) +- Intl: + . Fixed bug GH-12020 (intl_get_error_message() broken after + MessageFormatter::formatMessage() fails). (Girgias) + - ODBC: . Fixed memory leak with failed SQLPrepare. (NattyNarwhal) diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index 098c6a2b922..f6ec60fe199 100644 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.c @@ -98,7 +98,7 @@ PHP_FUNCTION( msgfmt_format_message ) intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set(/* intl_error* */ NULL, U_ILLEGAL_ARGUMENT_ERROR, "msgfmt_format_message: error converting pattern to UTF-16", 0 ); RETURN_FALSE; } @@ -113,7 +113,7 @@ PHP_FUNCTION( msgfmt_format_message ) #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { - intl_error_set( NULL, U_INVALID_FORMAT_ERROR, + intl_error_set(/* intl_error* */ NULL, U_INVALID_FORMAT_ERROR, "msgfmt_format_message: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } @@ -134,15 +134,14 @@ PHP_FUNCTION( msgfmt_format_message ) spprintf( &msg, 0, "pattern syntax error (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "unknown parser error" ); smart_str_free( &parse_error_str ); - intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( mfo ) ); - intl_errors_set_custom_msg( INTL_DATA_ERROR_P( mfo ), msg, 1 ); + /* Pass NULL to intl_error* parameter to store message in global Intl error msg stack */ + intl_error_set_code(/* intl_error* */ NULL, INTL_DATA_ERROR_CODE( mfo ) ); + intl_errors_set_custom_msg(/* intl_error* */ NULL, msg, 1 ); efree( msg ); } else { - intl_errors_set_custom_msg( INTL_DATA_ERROR_P(mfo), "Creating message formatter failed", 0 ); + intl_errors_set_custom_msg(/* intl_error* */ NULL, "Creating message formatter failed", 0 ); } - /* Reset custom error message as this is a static method that has no object */ - intl_errors_reset(INTL_DATA_ERROR_P(mfo)); umsg_close(MSG_FORMAT_OBJECT(mfo)); RETURN_FALSE; } diff --git a/ext/intl/tests/gh11658.phpt b/ext/intl/tests/gh11658.phpt index b29786255ca..f0cfab9280e 100644 --- a/ext/intl/tests/gh11658.phpt +++ b/ext/intl/tests/gh11658.phpt @@ -9,7 +9,13 @@ ini_set("intl.error_level", E_WARNING); $s = MessageFormatter::formatMessage('en', 'some {wrong.format}', []); var_dump($s); + +$s = msgfmt_format_message('en', 'some {wrong.format}', []); +var_dump($s); ?> --EXPECTF-- Warning: MessageFormatter::formatMessage(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}") in %s on line %d bool(false) + +Warning: msgfmt_format_message(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}") in %s on line %d +bool(false) diff --git a/ext/intl/tests/gh12020.phpt b/ext/intl/tests/gh12020.phpt new file mode 100644 index 00000000000..e4102606ca5 --- /dev/null +++ b/ext/intl/tests/gh12020.phpt @@ -0,0 +1,22 @@ +--TEST-- +GitHub #12020 intl_get_error_message() broken after MessageFormatter::formatMessage() fails +--EXTENSIONS-- +intl +--FILE-- + +--EXPECT-- +bool(false) +string(128) "pattern syntax error (parse error at offset 19, after " message with {", before or at "invalid format}"): U_PATTERN_SYNTAX_ERROR" +bool(false) +string(116) "pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}"): U_PATTERN_SYNTAX_ERROR" +bool(false) +string(128) "pattern syntax error (parse error at offset 19, after " message with {", before or at "invalid format}"): U_PATTERN_SYNTAX_ERROR" +bool(false) +string(116) "pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}"): U_PATTERN_SYNTAX_ERROR"