Commit 55f3138c5f1 for php
commit 55f3138c5f1308aa90646fd91db336defd249b3a
Merge: 682ee233e5d 3f28d393ef5
Author: Weilin Du <weilindu@php.net>
Date: Wed Nov 25 04:42:43 2026 +0800
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
ext/intl: Preserve the previous MessageFormatter pattern on failure (#25642)
diff --cc NEWS
index 8f684032bfc,3cdfc796952..9138f3586af
--- a/NEWS
+++ b/NEWS
@@@ -76,7 -84,11 +76,9 @@@ PH
- Intl:
. Fixed Locale::lookup() ignoring the default locale when the language tag
list is empty. (Weilin Du)
- . Fixed intl_error_name() truncating error codes outside the int range.
- (lacatoire)
. Fixed IntlCalendar::setTime() accepting non-finite timestamps. (Weilin Du)
+ . Fixed MessageFormatter::setPattern() losing the previous pattern when
+ the new pattern is invalid. (Weilin Du, David Carlier)
- JSON:
. Fixed json_decode() and json_validate() error messages. (lacatoire)
diff --cc ext/intl/msgformat/msgformat_attr.cpp
index e7ec006e5e7,25c960b956b..da68ef6fa95
--- a/ext/intl/msgformat/msgformat_attr.cpp
+++ b/ext/intl/msgformat/msgformat_attr.cpp
@@@ -16,7 -16,6 +16,11 @@@
#include <config.h>
#endif
++#include <memory>
++
++#include <unicode/msgfmt.h>
++
+extern "C" {
#include "php_intl.h"
#include "msgformat_class.h"
#include "msgformat_data.h"
@@@ -78,7 -76,9 +82,13 @@@ U_CFUNC PHP_FUNCTION( msgfmt_set_patter
}
#endif
- umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, &spattern_error, &INTL_DATA_ERROR_CODE(mfo));
- /* ICU may discard the old pattern if parsing the new one fails. */
- UMessageFormat *new_format = umsg_clone(MSG_FORMAT_OBJECT(mfo), &INTL_DATA_ERROR_CODE(mfo));
- umsg_applyPattern(new_format, spattern, spattern_len, &spattern_error, &INTL_DATA_ERROR_CODE(mfo));
++ icu::MessageFormat *mf = reinterpret_cast<icu::MessageFormat *>(MSG_FORMAT_OBJECT(mfo));
++ std::unique_ptr<icu::MessageFormat> new_mf(static_cast<icu::MessageFormat *>(mf->clone()));
++ if (!new_mf) {
++ INTL_DATA_ERROR_CODE(mfo) = U_MEMORY_ALLOCATION_ERROR;
++ } else {
++ new_mf->applyPattern(icu::UnicodeString(spattern, spattern_len), spattern_error, INTL_DATA_ERROR_CODE(mfo));
++ }
if (spattern) {
efree(spattern);
}
@@@ -90,6 -91,9 +100,9 @@@
RETURN_FALSE;
}
- umsg_close(MSG_FORMAT_OBJECT(mfo));
- MSG_FORMAT_OBJECT(mfo) = new_format;
++ delete mf;
++ MSG_FORMAT_OBJECT(mfo) = reinterpret_cast<UMessageFormat *>(new_mf.release());
+ mfo->mf_data.tz_set = 0;
if(mfo->mf_data.orig_format) {
efree(mfo->mf_data.orig_format);
}