@@ -33,6 +33,7 @@ TestMessageFormat2::runIndexedTest(int32_t index, UBool exec,
3333 TESTCASE_AUTO (testFormatterAPI);
3434 TESTCASE_AUTO (testHighLoneSurrogate);
3535 TESTCASE_AUTO (testLowLoneSurrogate);
36+ TESTCASE_AUTO (testLoneSurrogateInQuotedLiteral);
3637 TESTCASE_AUTO (dataDrivenTests);
3738 TESTCASE_AUTO_END;
3839}
@@ -350,7 +351,8 @@ void TestMessageFormat2::testHighLoneSurrogate() {
350351 .setPattern (loneSurrogate, pe, errorCode)
351352 .build (errorCode);
352353 UnicodeString result = msgfmt1.formatToString ({}, errorCode);
353- errorCode.expectErrorAndReset (U_MF_SYNTAX_ERROR, " testHighLoneSurrogate" );
354+ assertEquals (" testHighLoneSurrogate" , loneSurrogate, result);
355+ errorCode.errIfFailureAndReset (" testHighLoneSurrogate" );
354356}
355357
356358// ICU-22890 lone surrogate cause infinity loop
@@ -364,7 +366,25 @@ void TestMessageFormat2::testLowLoneSurrogate() {
364366 .setPattern (loneSurrogate, pe, errorCode)
365367 .build (errorCode);
366368 UnicodeString result = msgfmt2.formatToString ({}, errorCode);
367- errorCode.expectErrorAndReset (U_MF_SYNTAX_ERROR, " testLowLoneSurrogate" );
369+ assertEquals (" testLowLoneSurrogate" , loneSurrogate, result);
370+ errorCode.errIfFailureAndReset (" testLowLoneSurrogate" );
371+ }
372+
373+ void TestMessageFormat2::testLoneSurrogateInQuotedLiteral () {
374+ IcuTestErrorCode errorCode (*this , " testLoneSurrogateInQuotedLiteral" );
375+ UParseError pe = { 0 , 0 , {0 }, {0 } };
376+ // |\udc02|
377+ UnicodeString literal (" {|" );
378+ literal += 0xdc02 ;
379+ literal += " |}" ;
380+ UnicodeString expectedResult ({0xdc02 , 0 });
381+ icu::message2::MessageFormatter msgfmt2 =
382+ icu::message2::MessageFormatter::Builder (errorCode)
383+ .setPattern (literal, pe, errorCode)
384+ .build (errorCode);
385+ UnicodeString result = msgfmt2.formatToString ({}, errorCode);
386+ assertEquals (" testLoneSurrogateInQuotedLiteral" , expectedResult, result);
387+ errorCode.errIfFailureAndReset (" testLoneSurrogateInQuotedLiteral" );
368388}
369389
370390void TestMessageFormat2::dataDrivenTests () {
0 commit comments