diff --git a/icu4c/source/test/intltest/messageformat2test.cpp b/icu4c/source/test/intltest/messageformat2test.cpp index 524ee4ab79d9..48b6811dd853 100644 --- a/icu4c/source/test/intltest/messageformat2test.cpp +++ b/icu4c/source/test/intltest/messageformat2test.cpp @@ -30,6 +30,8 @@ TestMessageFormat2::runIndexedTest(int32_t index, UBool exec, TESTCASE_AUTO(testAPI); TESTCASE_AUTO(testAPISimple); TESTCASE_AUTO(testDataModelAPI); + TESTCASE_AUTO(testHighLoneSurrogate); + TESTCASE_AUTO(testLowLoneSurrogate); TESTCASE_AUTO(dataDrivenTests); TESTCASE_AUTO_END; } @@ -263,6 +265,30 @@ void TestMessageFormat2::testAPICustomFunctions() { delete person; } +// ICU-22890 lone surrogate cause infinity loop +void TestMessageFormat2::testHighLoneSurrogate() { + IcuTestErrorCode errorCode(*this, "testHighLoneSurrogate"); + UParseError pe = { 0, 0, {0}, {0} }; + // Lone surrogate with only high surrogate + UnicodeString loneSurrogate({0xda02, 0}); + icu::message2::MessageFormatter msgfmt1 = + icu::message2::MessageFormatter::Builder(errorCode) + .setPattern(loneSurrogate, pe, errorCode) + .build(errorCode); +} + +// ICU-22890 lone surrogate cause infinity loop +void TestMessageFormat2::testLowLoneSurrogate() { + IcuTestErrorCode errorCode(*this, "testLowLoneSurrogate"); + UParseError pe = { 0, 0, {0}, {0} }; + // Lone surrogate with only low surrogate + UnicodeString loneSurrogate({0xdc02, 0}); + icu::message2::MessageFormatter msgfmt2 = + icu::message2::MessageFormatter::Builder(errorCode) + .setPattern(loneSurrogate, pe, errorCode) + .build(errorCode); +} + void TestMessageFormat2::dataDrivenTests() { IcuTestErrorCode errorCode(*this, "jsonTests"); diff --git a/icu4c/source/test/intltest/messageformat2test.h b/icu4c/source/test/intltest/messageformat2test.h index 7c7c2612f50d..b4b250cb5106 100644 --- a/icu4c/source/test/intltest/messageformat2test.h +++ b/icu4c/source/test/intltest/messageformat2test.h @@ -87,6 +87,8 @@ class TestMessageFormat2: public IntlTest { void testMessageFormatDateTimeSkeleton(message2::TestCase::Builder&, IcuTestErrorCode&); void testMf1Behavior(message2::TestCase::Builder&, IcuTestErrorCode&); + void testHighLoneSurrogate(void); + void testLowLoneSurrogate(void); }; // class TestMessageFormat2 U_NAMESPACE_BEGIN