mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-12849 Title Casing, incorrect length returned when preflighting with a NULL output buffer.
X-SVN-Rev: 39518
This commit is contained in:
parent
a19a3a0f7a
commit
52989746d9
4 changed files with 40 additions and 0 deletions
|
@ -422,6 +422,9 @@ ucasemap_internalUTF8ToTitle(const UCaseMap *csm,
|
|||
src, &csc,
|
||||
titleLimit, idx,
|
||||
pErrorCode);
|
||||
if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
|
||||
*pErrorCode=U_ZERO_ERROR;
|
||||
}
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
return destIndex;
|
||||
}
|
||||
|
|
|
@ -305,6 +305,9 @@ ustrcase_internalToTitle(const UCaseMap *csm,
|
|||
src, &csc,
|
||||
titleLimit, idx,
|
||||
pErrorCode);
|
||||
if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
|
||||
*pErrorCode=U_ZERO_ERROR;
|
||||
}
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
return destIndex;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ StringCaseTest::runIndexedTest(int32_t index, UBool exec, const char *&name, cha
|
|||
TESTCASE_AUTO(TestGreekUpper);
|
||||
TESTCASE_AUTO(TestLongUpper);
|
||||
TESTCASE_AUTO(TestMalformedUTF8);
|
||||
TESTCASE_AUTO(TestBufferOverflow);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
|
@ -815,3 +816,35 @@ void StringCaseTest::TestMalformedUTF8() {
|
|||
errorCode.errorName(), (int)destLength, dest[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void StringCaseTest::TestBufferOverflow() {
|
||||
// Ticket #12849, incorrect result from Title Case preflight operation,
|
||||
// when buffer overflow error is expected.
|
||||
IcuTestErrorCode errorCode(*this, "TestBufferOverflow");
|
||||
LocalUCaseMapPointer csm(ucasemap_open("en", 0, errorCode));
|
||||
if (errorCode.isFailure()) {
|
||||
errln("ucasemap_open(English) failed - %s", errorCode.errorName());
|
||||
return;
|
||||
}
|
||||
|
||||
UnicodeString data("hello world");
|
||||
int32_t result = ucasemap_toTitle(csm.getAlias(), NULL, 0, data.getBuffer(), data.length(), errorCode);
|
||||
if (errorCode.get() != U_BUFFER_OVERFLOW_ERROR || result != data.length()) {
|
||||
errln("%s:%d ucasemap_toTitle(\"hello world\") failed: "
|
||||
"expected (U_BUFFER_OVERFLOW_ERROR, %d), got (%s, %d)",
|
||||
__FILE__, __LINE__, data.length(), errorCode.errorName(), result);
|
||||
}
|
||||
errorCode.reset();
|
||||
|
||||
#if U_HAVE_STD_STRING
|
||||
std::string data_utf8;
|
||||
data.toUTF8String(data_utf8);
|
||||
result = ucasemap_utf8ToTitle(csm.getAlias(), NULL, 0, data_utf8.c_str(), data_utf8.length(), errorCode);
|
||||
if (errorCode.get() != U_BUFFER_OVERFLOW_ERROR || result != (int32_t)data_utf8.length()) {
|
||||
errln("%s:%d ucasemap_toTitle(\"hello world\") failed: "
|
||||
"expected (U_BUFFER_OVERFLOW_ERROR, %d), got (%s, %d)",
|
||||
__FILE__, __LINE__, data_utf8.length(), errorCode.errorName(), result);
|
||||
}
|
||||
errorCode.reset();
|
||||
#endif // U_HAVE_STD_STRING
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ public:
|
|||
void TestGreekUpper();
|
||||
void TestLongUpper();
|
||||
void TestMalformedUTF8();
|
||||
void TestBufferOverflow();
|
||||
|
||||
private:
|
||||
void assertGreekUpper(const char *s, const char *expected);
|
||||
|
|
Loading…
Add table
Reference in a new issue