diff options
Diffstat (limited to 'ext/intl/msgformat/msgformat_format.c')
-rw-r--r-- | ext/intl/msgformat/msgformat_format.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index a11c167a4b..a0a410cf0d 100644 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.c @@ -94,6 +94,7 @@ PHP_FUNCTION( msgfmt_format_message ) size_t slocale_len = 0; MessageFormatter_object mf; MessageFormatter_object *mfo = &mf; + UParseError parse_error; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "ssa", @@ -136,10 +137,25 @@ PHP_FUNCTION( msgfmt_format_message ) #endif /* Create an ICU message formatter. */ - MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo)); + MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, &parse_error, &INTL_DATA_ERROR_CODE(mfo)); if(spattern && spattern_len) { efree(spattern); } + + if (INTL_DATA_ERROR_CODE( mfo ) == U_PATTERN_SYNTAX_ERROR) { + char *msg = NULL; + smart_str parse_error_str; + parse_error_str = intl_parse_error_to_string( &parse_error ); + 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 ); + + efree( msg ); + RETURN_FALSE; + } + INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed"); msgfmt_do_format(mfo, args, return_value); |