diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9746f79d9ae51845c9b997929916b6f83a0cc140..b8ecc8d5d40ed84cd0fb697b34a6c2f43b465cc4 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4539,13 +4539,24 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ regex_t regex; char regErrBuf[256] = {0}; - const char* pattern = pRight->value.pz; + //remove the quote at the begin end of original sql string. + uint32_t lenPattern = pRight->exprToken.n - 2; + char* pattern = malloc(lenPattern + 1); + strncpy(pattern, pRight->exprToken.z+1, lenPattern); + pattern[lenPattern] = '\0'; + + tfree(pRight->value.pz); + pRight->value.pz = strndup(pattern, lenPattern); + pRight->value.nLen = lenPattern; + int cflags = REG_EXTENDED; if ((errCode = regcomp(®ex, pattern, cflags)) != 0) { regerror(errCode, ®ex, regErrBuf, sizeof(regErrBuf)); tscError("Failed to compile regex pattern %s. reason %s", pattern, regErrBuf); + free(pattern); return invalidOperationMsg(msgBuf, msg3); } + free(pattern); regfree(®ex); } diff --git a/tests/script/general/parser/regex.sim b/tests/script/general/parser/regex.sim index eed36018d4c04ec5752e64105d025347982bfcb0..6d87e1cd7c6c6620eabb44e66195aab3cb177494 100644 --- a/tests/script/general/parser/regex.sim +++ b/tests/script/general/parser/regex.sim @@ -79,6 +79,23 @@ if $rows != 1 then return -1 endi +sql select c1b from $st_name where c1b match '\\.\\*' +if $rows != 0 then + return -1 +endi + +sql select c1b from $st_name where c1b match '\\\\' +if $rows != 0 then + return -1 +endi + +sql insert into $ct1_name values(now+3s, '\\this is engine') + +sql select c1b from $st_name where c1b match '\\' +if $rows != 1 then + return -1 +endi + sql_error select c1b from $st_name where c1b match e; sql_error select c1b from $st_name where c1b nmatch e;