From 84faef50ab67cb1a130f66219cdd832aca92437f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 16 Dec 2021 13:05:58 +0800 Subject: [PATCH] =?UTF-8?q?[TD-11201]=20strRmquoteEscape=20=E6=9C=89b?= =?UTF-8?q?ug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/src/tutil.c | 4 ++-- src/util/tests/stringTest.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index b27196da65..02498e2222 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -57,9 +57,8 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } - +// delete escape character: \\, \', \" int32_t strRmquote(char *z, int32_t len){ - // delete escape character: \\, \', \" char delim = 0; int32_t cnt = 0; int32_t j = 0; @@ -82,6 +81,7 @@ int32_t strRmquote(char *z, int32_t len){ z[j] = z[k]; j++; } + z[j] = 0; return j; } diff --git a/src/util/tests/stringTest.cpp b/src/util/tests/stringTest.cpp index 97a994f544..e304ccaec6 100644 --- a/src/util/tests/stringTest.cpp +++ b/src/util/tests/stringTest.cpp @@ -8,24 +8,40 @@ TEST(testCase, str_rmquote_test) { char t1[] = "\"\".dd"; - int32_t len = strRmquote(t1); - + int32_t len = strRmquote(t1, strlen(t1)); printf("t1:%s, len:%d\n", t1, len); + EXPECT_EQ(3, len); + EXPECT_STRCASEEQ(t1, ".dd"); char t2[] = "\"fsd\\\"fs\".dd"; - len = strRmquote(t2); - + len = strRmquote(t2, strlen(t2)); printf("t2:%s, len:%d\n", t2, len); + EXPECT_EQ(9, len); + EXPECT_STRCASEEQ(t2, "fsd\"fs.dd"); char t3[] = "fs\\_d\\%.d\\d"; - len = strRmquote(t3); - + len = strRmquote(t3, strlen(t3)); printf("t3:%s, len:%d\n", t3, len); + EXPECT_EQ(10, len); + EXPECT_STRCASEEQ(t3, "fs\\_d\\%.dd"); char t4[] = "\"fs\\_d\\%\".dd"; - len = strRmquote(t4); - + len = strRmquote(t4, strlen(t4)); printf("t4:%s, len:%d\n", t4, len); + EXPECT_EQ(10, len); + EXPECT_STRCASEEQ(t4, "fs\\_d\\%.dd"); + + char t5[] = "\"fs\\_d\\%\""; + len = strRmquote(t5, strlen(t5)); + printf("t5:%s, len:%d\n", t5, len); + EXPECT_EQ(7, len); + EXPECT_STRCASEEQ(t5, "fs\\_d\\%"); + + char t6[] = "'fs\\_d\\%'"; + len = strRmquote(t6, strlen(t6)); + printf("t6:%s, len:%d\n", t6, len); + EXPECT_EQ(7, len); + EXPECT_STRCASEEQ(t6, "fs\\_d\\%"); } TEST(testCase, string_dequote_test) { -- GitLab