@@ -31,6 +31,8 @@ TestMessageFormat2::runIndexedTest(int32_t index, UBool exec,
3131 TESTCASE_AUTO (testAPISimple);
3232 TESTCASE_AUTO (testDataModelAPI);
3333 TESTCASE_AUTO (testFormatterAPI);
34+ TESTCASE_AUTO (testHighLoneSurrogate);
35+ TESTCASE_AUTO (testLowLoneSurrogate);
3436 TESTCASE_AUTO (dataDrivenTests);
3537 TESTCASE_AUTO_END;
3638}
@@ -337,6 +339,34 @@ void TestMessageFormat2::testAPICustomFunctions() {
337339 delete person;
338340}
339341
342+ // ICU-22890 lone surrogate cause infinity loop
343+ void TestMessageFormat2::testHighLoneSurrogate () {
344+ IcuTestErrorCode errorCode (*this , " testHighLoneSurrogate" );
345+ UParseError pe = { 0 , 0 , {0 }, {0 } };
346+ // Lone surrogate with only high surrogate
347+ UnicodeString loneSurrogate ({0xda02 , 0 });
348+ icu::message2::MessageFormatter msgfmt1 =
349+ icu::message2::MessageFormatter::Builder (errorCode)
350+ .setPattern (loneSurrogate, pe, errorCode)
351+ .build (errorCode);
352+ UnicodeString result = msgfmt1.formatToString ({}, errorCode);
353+ errorCode.expectErrorAndReset (U_MF_SYNTAX_ERROR, " testHighLoneSurrogate" );
354+ }
355+
356+ // ICU-22890 lone surrogate cause infinity loop
357+ void TestMessageFormat2::testLowLoneSurrogate () {
358+ IcuTestErrorCode errorCode (*this , " testLowLoneSurrogate" );
359+ UParseError pe = { 0 , 0 , {0 }, {0 } };
360+ // Lone surrogate with only low surrogate
361+ UnicodeString loneSurrogate ({0xdc02 , 0 });
362+ icu::message2::MessageFormatter msgfmt2 =
363+ icu::message2::MessageFormatter::Builder (errorCode)
364+ .setPattern (loneSurrogate, pe, errorCode)
365+ .build (errorCode);
366+ UnicodeString result = msgfmt2.formatToString ({}, errorCode);
367+ errorCode.expectErrorAndReset (U_MF_SYNTAX_ERROR, " testLowLoneSurrogate" );
368+ }
369+
340370void TestMessageFormat2::dataDrivenTests () {
341371 IcuTestErrorCode errorCode (*this , " jsonTests" );
342372
0 commit comments