diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/current_room_state_table.go b/src/github.com/matrix-org/dendrite/syncapi/storage/current_room_state_table.go index 2bc3fdde8..7278573ca 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/current_room_state_table.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/current_room_state_table.go @@ -69,10 +69,10 @@ const selectRoomIDsWithMembershipSQL = "" + const selectCurrentStateSQL = "" + "SELECT event_json FROM syncapi_current_room_state WHERE room_id = $1" + - " AND ( $2::text[] IS NULL OR sender = ANY($2) )" + - " AND ( $3::text[] IS NULL OR NOT(sender = ANY($3)) )" + - " AND ( $4::text[] IS NULL OR type = ANY($4) )" + - " AND ( $5::text[] IS NULL OR NOT(type = ANY($5)) )" + " AND ( $2::text[] IS NULL OR sender = ANY($2) )" + + " AND ( $3::text[] IS NULL OR NOT(sender = ANY($3)) )" + + " AND ( $4::text[] IS NULL OR type LIKE ANY($4) )" + + " AND ( $5::text[] IS NULL OR NOT(type LIKE ANY($5)) )" const selectJoinedUsersSQL = "" + "SELECT room_id, state_key FROM syncapi_current_room_state WHERE type = 'm.room.member' AND membership = 'join'" @@ -187,8 +187,8 @@ func (s *currentRoomStateStatements) selectCurrentState( rows, err := stmt.QueryContext(ctx, roomID, pq.StringArray(filter.Senders), pq.StringArray(filter.NotSenders), - pq.StringArray(filter.Types), - pq.StringArray(filter.NotTypes)) + pq.StringArray(filterConvertWildcardToSQL(filter.Types)), + pq.StringArray(filterConvertWildcardToSQL(filter.NotTypes))) if err != nil { return nil, err } diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go b/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go index 21ab25877..886e48c3d 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/filtering.go @@ -15,6 +15,8 @@ package storage import ( + "strings" + "github.com/matrix-org/gomatrix" ) @@ -46,3 +48,11 @@ func hasValue(value string, list []string) bool { } return false } + +func filterConvertWildcardToSQL(values []string) []string { + ret := make([]string, len(values)) + for i := range values { + ret[i] = strings.Replace(values[i], "*", "%", -1) + } + return ret +} diff --git a/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go b/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go index 1bc5bf3ac..a45c90331 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go +++ b/src/github.com/matrix-org/dendrite/syncapi/storage/output_room_events_table.go @@ -75,10 +75,10 @@ const selectRoomRecentEventsSQL = "" + "SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" + " WHERE room_id=$1 " + " AND id > $2 AND id <= $3" + - " AND ( $4::text[] IS NULL OR sender = ANY($4) )" + - " AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" + - " AND ( $6::text[] IS NULL OR type = ANY($6) )" + - " AND ( $7::text[] IS NULL OR NOT(type = ANY($7)) )" + + " AND ( $4::text[] IS NULL OR sender = ANY($4) )" + + " AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" + + " AND ( $6::text[] IS NULL OR type LIKE ANY($6) )" + + " AND ( $7::text[] IS NULL OR NOT(type LIKE ANY($7)) )" + " ORDER BY id DESC LIMIT $8" const selectMaxEventIDSQL = "" + @@ -244,8 +244,8 @@ func (s *outputRoomEventsStatements) selectRoomRecentEvents( rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos, pq.StringArray(timelineFilter.Senders), pq.StringArray(timelineFilter.NotSenders), - pq.StringArray(timelineFilter.Types), - pq.StringArray(timelineFilter.NotTypes), + pq.StringArray(filterConvertWildcardToSQL(timelineFilter.Types)), + pq.StringArray(filterConvertWildcardToSQL(timelineFilter.NotTypes)), timelineFilter.Limit+1, // TODO: limit abusive values? This can also be done in gomatrix.Filter.Validate ) if err != nil {