3
0

Fix parsing og sort string

By trimming extra inverted quotes from the sort string
This commit is contained in:
Vivek Patel
2022-12-02 20:04:42 +05:30
parent 3e00b38e2f
commit d7d8d9e7a9

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"regexp"
"strings"
"github.com/cortezaproject/corteza/server/pkg/slice"
@@ -128,19 +129,24 @@ func splitCommaParenthesis(in string) (out []string) {
depth--
case ',':
if depth == 0 {
out = append(out, strings.TrimSpace(in[start:i]))
out = append(out, trimQuotes(strings.TrimSpace(in[start:i])))
start = i + 1
}
}
}
if start < len(in) {
out = append(out, strings.TrimSpace(in[start:]))
out = append(out, trimQuotes(strings.TrimSpace(in[start:])))
}
return
}
// trimQuotes removes quotes from the beginning and the end of the string
func trimQuotes(in string) string {
return regexp.MustCompile(`^"(.*)"$`).ReplaceAllString(in, `$1`)
}
// UnmarshalJSON parses sort expression when passed inside JSON
func (set *SortExprSet) UnmarshalJSON(in []byte) error {
// This is an edgecase where `sort: ""` is passed in