From b721486890dfb2614329ab55333d3ef146eb15ee Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 4 Jun 2021 16:21:25 +0800 Subject: [PATCH] fix tag string quote issue --- src/common/src/tvariant.c | 2 +- src/util/inc/tutil.h | 1 + src/util/src/tutil.c | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 9988450c30..33dab51633 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -74,7 +74,7 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) { case TSDB_DATA_TYPE_BINARY: { pVar->pz = strndup(token->z, token->n); - pVar->nLen = strdequote(pVar->pz); + pVar->nLen = strRmquote(pVar->pz, token->n); break; } diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index fe5c038c51..7c8fd2ed83 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -26,6 +26,7 @@ extern "C" { #include "taosdef.h" int32_t strdequote(char *src); +int32_t strRmquote(char *z, int32_t len); size_t strtrim(char *src); char * strnchr(char *haystack, char needle, int32_t len, bool skipquote); char ** strsplit(char *src, const char *delim, int32_t *num); diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 451976f563..70285eb3cc 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -52,6 +52,33 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } + +int32_t strRmquote(char *z, int32_t len){ + // delete escape character: \\, \', \" + char delim = z[0]; + + int32_t cnt = 0; + int32_t j = 0; + for (uint32_t k = 1; k < len - 1; ++k) { + if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { + z[j] = z[k + 1]; + + cnt++; + j++; + k++; + continue; + } + + z[j] = z[k]; + j++; + } + + z[j] = 0; + + return len - 2 - cnt; +} + + size_t strtrim(char *z) { int32_t i = 0; int32_t j = 0; -- GitLab