mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.3'
* PHP-8.3: Fixed bug GH-12020: intl_get_error_message() broken after MessageFormatter::formatMessage() fails
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
22
ext/intl/tests/gh12020.phpt
Normal file
22
ext/intl/tests/gh12020.phpt
Normal file
@@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
GitHub #12020 intl_get_error_message() broken after MessageFormatter::formatMessage() fails
|
||||
--EXTENSIONS--
|
||||
intl
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(\MessageFormatter::formatMessage('en', 'some message with {invalid format}', []), intl_get_error_message());
|
||||
var_dump(\MessageFormatter::formatMessage('en', 'some {wrong.format}', []), intl_get_error_message());
|
||||
|
||||
var_dump(msgfmt_format_message('en', 'some message with {invalid format}', []), intl_get_error_message());
|
||||
var_dump(msgfmt_format_message('en', 'some {wrong.format}', []), intl_get_error_message());
|
||||
?>
|
||||
--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"
|
||||
Reference in New Issue
Block a user