Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix: postgres encoding error doing searches

goenningfd5ef3bff481
diff --git a/app/services/sqlstore/postgres/common.go b/app/services/sqlstore/postgres/common.go
index 2a0aeee99..8a0437c87 100644
--- a/app/services/sqlstore/postgres/common.go
+++ b/app/services/sqlstore/postgres/common.go
@@ -19,6 +19,12 @@ func ToTSQuery(input string) string {
return strings.Join(strings.Fields(input), "|")
}
+// SanitizeString converts input to another string that only contains utf-8 characters and not-null characters
+func SanitizeString(input string) string {
+ input = strings.Replace(input, "\u0000", "", -1)
+ return strings.ToValidUTF8(input, "")
+}
+
func getViewData(view string) (string, []enum.PostStatus, string) {
var (
condition string
diff --git a/app/services/sqlstore/postgres/post.go b/app/services/sqlstore/postgres/post.go
index c1c49cd54..e6b86a839 100644
--- a/app/services/sqlstore/postgres/post.go
+++ b/app/services/sqlstore/postgres/post.go
@@ -392,7 +392,7 @@ func searchPosts(ctx context.Context, q *query.SearchPosts) error {
enum.PostPlanned,
enum.PostCompleted,
enum.PostDeclined,
- }), ToTSQuery(q.Query), q.Query)
+ }), ToTSQuery(q.Query), SanitizeString(q.Query))
} else {
condition, statuses, sort := getViewData(q.View)
sql := fmt.Sprintf(`