Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICU-22890 MF2: Add lone surrogate test to parser #3167

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions icu4c/source/test/intltest/messageformat2test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ TestMessageFormat2::runIndexedTest(int32_t index, UBool exec,
TESTCASE_AUTO(testAPISimple);
TESTCASE_AUTO(testDataModelAPI);
TESTCASE_AUTO(testFormatterAPI);
TESTCASE_AUTO(testHighLoneSurrogate);
TESTCASE_AUTO(testLowLoneSurrogate);
TESTCASE_AUTO(dataDrivenTests);
TESTCASE_AUTO_END;
}
Expand Down Expand Up @@ -337,6 +339,34 @@ 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);
UnicodeString result = msgfmt1.formatToString({}, errorCode);
errorCode.expectErrorAndReset(U_MF_SYNTAX_ERROR, "testHighLoneSurrogate");
}

// 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);
UnicodeString result = msgfmt2.formatToString({}, errorCode);
errorCode.expectErrorAndReset(U_MF_SYNTAX_ERROR, "testLowLoneSurrogate");
}

void TestMessageFormat2::dataDrivenTests() {
IcuTestErrorCode errorCode(*this, "jsonTests");

Expand Down
2 changes: 2 additions & 0 deletions icu4c/source/test/intltest/messageformat2test.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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
Expand Down