From a3d0ae47b6f28c3ee3c0d3309b4b6f3d64ce369c Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Wed, 7 Nov 2001 03:23:55 +0000 Subject: [PATCH] ICU-1098 Fix parsing of escapes. X-SVN-Rev: 6658 --- icu4c/source/test/cintltst/callcoll.c | 55 ++++++++++++++++++++++++ icu4c/source/test/testdata/testtypes.txt | 2 +- icu4c/source/tools/genrb/read.c | 16 +++---- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/icu4c/source/test/cintltst/callcoll.c b/icu4c/source/test/cintltst/callcoll.c index cb1d59d96f2..6315825bbbd 100644 --- a/icu4c/source/test/cintltst/callcoll.c +++ b/icu4c/source/test/cintltst/callcoll.c @@ -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 diff --git a/icu4c/source/test/testdata/testtypes.txt b/icu4c/source/test/testdata/testtypes.txt index 6fccf2a67e2..4e5e84ce2dc 100644 --- a/icu4c/source/test/testdata/testtypes.txt +++ b/icu4c/source/test/testdata/testtypes.txt @@ -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 diff --git a/icu4c/source/tools/genrb/read.c b/icu4c/source/tools/genrb/read.c index bfae09da3a1..d7b863bec41 100644 --- a/icu4c/source/tools/genrb/read.c +++ b/icu4c/source/tools/genrb/read.c @@ -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; }