mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-1098 Fix parsing of escapes.
X-SVN-Rev: 6658
This commit is contained in:
parent
2506f08b4e
commit
a3d0ae47b6
3 changed files with 63 additions and 10 deletions
|
@ -222,6 +222,8 @@ const UChar testCases[][4] =
|
|||
|
||||
#ifndef INCLUDE_CALLCOLL_C
|
||||
|
||||
static void TestJitterbug1098();
|
||||
|
||||
void addAllCollTest(TestNode** root)
|
||||
{
|
||||
|
||||
|
@ -236,6 +238,8 @@ void addAllCollTest(TestNode** root)
|
|||
addTest(root, &TestSurrogates, "tscoll/callcoll/TestSurrogates");
|
||||
addTest(root, &TestInvalidRules, "tscoll/callcoll/TestInvalidRules");
|
||||
addTest(root, &TestJB1401, "tscoll/callcoll/TestJB1401");
|
||||
addTest(root, &TestJitterbug1098, "tscoll/callcoll/TestJitterbug1098");
|
||||
|
||||
}
|
||||
|
||||
static void doTestVariant(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result)
|
||||
|
@ -793,5 +797,56 @@ TestInvalidRules(){
|
|||
}
|
||||
}
|
||||
}
|
||||
static void
|
||||
TestJitterbug1098(){
|
||||
UChar rule[1000];
|
||||
UCollator* c1 = NULL;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UParseError parseError;
|
||||
int32_t length = 1000;
|
||||
char preContext[200]={0};
|
||||
char postContext[200]={0};
|
||||
const UChar* retRule=NULL;
|
||||
int i=0;
|
||||
const char* rules[] = {
|
||||
"&''<\\\\",
|
||||
"&\\'<\\\\",
|
||||
"&\\\"<'\\'",
|
||||
"&'\"'<\\'",
|
||||
'\0'
|
||||
|
||||
};
|
||||
const UCollationResult results[] = {
|
||||
UCOL_LESS,
|
||||
UCOL_LESS,
|
||||
UCOL_LESS,
|
||||
UCOL_LESS,
|
||||
};
|
||||
const UChar input[][2]= {
|
||||
{0x0027,0x005c},
|
||||
{0x0027,0x005c},
|
||||
{0x0022,0x005c},
|
||||
{0x0022,0x0027},
|
||||
};
|
||||
UChar X[2] ={0};
|
||||
UChar Y[2] ={0};
|
||||
u_memset(parseError.preContext,0x0000,U_PARSE_CONTEXT_LEN);
|
||||
u_memset(parseError.postContext,0x0000,U_PARSE_CONTEXT_LEN);
|
||||
for(;rules[i]!=0;i++){
|
||||
u_uastrcpy(rule, rules[i]);
|
||||
c1 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, &parseError, &status);
|
||||
if(U_FAILURE(status)){
|
||||
u_UCharsToChars(parseError.preContext,preContext,20);
|
||||
u_UCharsToChars(parseError.postContext,postContext,20);
|
||||
log_err("Could not parse the rules syntax. Error: %s ", u_errorName(status));
|
||||
log_verbose("\n\tPre-Context: %s \n\tPost-Context:%s \n",preContext,postContext);
|
||||
return;
|
||||
}
|
||||
X[0] = input[i][0];
|
||||
Y[0] = input[i][1];
|
||||
doTest(c1,X,Y,results[i]);
|
||||
ucol_close(c1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
2
icu4c/source/test/testdata/testtypes.txt
vendored
2
icu4c/source/test/testdata/testtypes.txt
vendored
|
@ -29,7 +29,7 @@ testtypes
|
|||
emptyarray:array
|
||||
{
|
||||
}
|
||||
testescape{ "tab:\t cr:\r ff:\f newline:\n backslash:\\ quote=\' doubleQuote=\" singlequoutes=''" }
|
||||
testescape{ "tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''" }
|
||||
string{ }
|
||||
stringTable{{}}
|
||||
//nested table
|
||||
|
|
|
@ -174,18 +174,16 @@ static enum ETokenType getStringToken(UCHARBUF* buf,
|
|||
if (c == U_ERR) {
|
||||
return TOK_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
U_APPEND_CHAR32(c, pTarget,len);
|
||||
pTarget = target;
|
||||
ustr_uscat(token, pTarget,len, status);
|
||||
isFollowingCharEscaped = FALSE;
|
||||
len=0;
|
||||
|
||||
}
|
||||
if(c==ESCAPE && !isFollowingCharEscaped){
|
||||
isFollowingCharEscaped = TRUE;
|
||||
}else{
|
||||
U_APPEND_CHAR32(c, pTarget,len);
|
||||
pTarget = target;
|
||||
ustr_uscat(token, pTarget,len, status);
|
||||
isFollowingCharEscaped = FALSE;
|
||||
len=0;
|
||||
}
|
||||
|
||||
if (U_FAILURE(*status)) {
|
||||
return TOK_ERROR;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue