@@ -27,12 +27,18 @@ class PostgresChangeFilter(private val event: String, private val schema: String
27
27
*/
28
28
fun filter (filter : FilterOperation ) {
29
29
val filterValue = when (filter.operator ) {
30
- FilterOperator .EQ , FilterOperator .NEQ , FilterOperator .GT , FilterOperator .GTE , FilterOperator .LT , FilterOperator .LTE -> filter.value.toString()
30
+ FilterOperator .EQ ,
31
+ FilterOperator .NEQ ,
32
+ FilterOperator .GT ,
33
+ FilterOperator .GTE ,
34
+ FilterOperator .LT ,
35
+ FilterOperator .LTE ->
36
+ escapeValue(filter.value)
31
37
FilterOperator .IN -> {
32
38
if (filter.value is List <* >) {
33
- (filter.value as List <* >).joinToString(" ," , prefix = " (" , postfix = " )" ) { it.toString( ) }
39
+ (filter.value as List <* >).joinToString(" ," , prefix = " (" , postfix = " )" ) { escapeValue(it ) }
34
40
} else {
35
- filter.value.toString( )
41
+ escapeValue( filter.value)
36
42
}
37
43
}
38
44
else -> throw UnsupportedOperationException (" Unsupported filter operator: ${filter.operator } " )
@@ -53,4 +59,17 @@ class PostgresChangeFilter(private val event: String, private val schema: String
53
59
@SupabaseInternal
54
60
fun buildConfig () = PostgresJoinConfig (schema, table, filter, event)
55
61
56
- }
62
+ }
63
+
64
+ private val quotedCharacters = listOf (" ," , " ." , " :" , " (" , " )" )
65
+
66
+ private fun escapeValue (value : Any? ): String {
67
+ val asString = value.toString()
68
+ .replace(" \\ " , " \\\\ " )
69
+ .replace(" \" " , " \\\" " )
70
+ return if (quotedCharacters.any { asString.contains(it) }) {
71
+ " \" $asString \" "
72
+ } else {
73
+ asString
74
+ }
75
+ }
0 commit comments