Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: escape single quotes in Infinity SQL filter conditions (#14186)

euvre84b6069ec745
diff --git a/common/doc_store/infinity_conn_base.py b/common/doc_store/infinity_conn_base.py
index 1336c92c5b..20baa34a60 100644
--- a/common/doc_store/infinity_conn_base.py
+++ b/common/doc_store/infinity_conn_base.py
@@ -187,7 +187,8 @@ class InfinityConnectionBase(DocStoreConnection):
strInCond = f"({strInCond})"
cond.append(strInCond)
else:
- cond.append(f"filter_fulltext('{self.convert_matching_field(k)}', '{v}')")
+ escaped_v = str(v).replace("'", "''")
+ cond.append(f"filter_fulltext('{self.convert_matching_field(k)}', '{escaped_v}')")
elif isinstance(v, list):
inCond = list()
for item in v:
@@ -206,7 +207,8 @@ class InfinityConnectionBase(DocStoreConnection):
if kk == "exists":
cond.append("NOT (%s)" % exists(vv))
elif isinstance(v, str):
- cond.append(f"{k}='{v}'")
+ escaped_v = v.replace("'", "''")
+ cond.append(f"{k}='{escaped_v}'")
elif k == "exists":
cond.append(exists(v))
else: