99QueryValue = str | bool | dt .date | dt .datetime | Numeric
1010
1111
12- def parse_kwargs (query_dict : dict [str , QueryValue ]) -> list [str ]: # noqa: WPS231
12+ def quote_rql_value (value : str ) -> str :
13+ """Wrap value in single quotes for RQL comparison operators."""
14+ escaped_value = value .replace ("'" , r"\'" )
15+ return f"'{ escaped_value } '"
16+
17+
18+ def parse_kwargs (query_dict : dict [str , QueryValue ]) -> list [str ]: # noqa: WPS231 C901
1319 """
1420 Parse keyword arguments into RQL query expressions.
1521
@@ -26,7 +32,7 @@ def parse_kwargs(query_dict: dict[str, QueryValue]) -> list[str]: # noqa: WPS23
2632
2733 Examples:
2834 parse_kwargs({'name': 'John', 'age__gt': 25})
29- [' eq(name,John)', ' gt(age,25)' ]
35+ [" eq(name,' John')", " gt(age,'25')" ]
3036
3137 parse_kwargs({'status__in': ['active', 'pending']})
3238 ['in(status,(active,pending))']
@@ -37,17 +43,21 @@ def parse_kwargs(query_dict: dict[str, QueryValue]) -> list[str]: # noqa: WPS23
3743 if len (tokens ) == 1 :
3844 field = tokens [0 ]
3945 str_value = rql_encode ("eq" , value )
46+ str_value = quote_rql_value (str_value )
4047 query .append (f"eq({ field } ,{ str_value } )" )
4148 continue
4249 op = tokens [- 1 ]
4350 if op not in constants .KEYWORDS :
4451 field = "." .join (tokens )
4552 str_value = rql_encode ("eq" , value )
53+ str_value = quote_rql_value (str_value )
4654 query .append (f"eq({ field } ,{ str_value } )" )
4755 continue
4856 field = "." .join (tokens [:- 1 ])
4957 if op in constants .COMP or op in constants .SEARCH :
5058 str_value = rql_encode (op , value )
59+ if op in constants .COMP :
60+ str_value = quote_rql_value (str_value )
5161 query .append (f"{ op } ({ field } ,{ str_value } )" )
5262 continue
5363 if op in constants .LIST :
@@ -462,6 +472,8 @@ def ilike(self, value: QueryValue) -> Self:
462472 def _bin (self , op : str , value : QueryValue ) -> Self :
463473 self ._field = "." .join (self ._path )
464474 value = rql_encode (op , value )
475+ if op in constants .COMP :
476+ value = quote_rql_value (value )
465477 self .expr = f"{ op } ({ self ._field } ,{ value } )"
466478 return self
467479
0 commit comments