Fix policy encoding to string #104

Merged
fyrchik merged 2 commits from alexvanin/frostfs-sdk-go:fix/policy-encode-characters into master 2023-07-07 09:33:02 +00:00
2 changed files with 14 additions and 1 deletions

View File

@ -471,7 +471,7 @@ func writeFilterStringTo(w io.StringWriter, f netmap.Filter) error {
unspecified := op == 0
if s = f.GetKey(); s != "" {
_, err = w.WriteString(fmt.Sprintf("%s %s %s", s, op, f.GetValue()))
_, err = w.WriteString(fmt.Sprintf("%s %s %s", escapeString(s), op, escapeString(f.GetValue())))
if err != nil {
return err
}
@ -816,3 +816,12 @@ func operationFromString(s string) (op netmap.Operation) {
return
}
// escapeString returns single quote wrapped string if it contains special
// characters '-' and whitespace.
func escapeString(s string) string {
if strings.ContainsAny(s, " -\t") {
return "'" + s + "'"
}
return s
}

View File

@ -31,6 +31,10 @@ FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS
`UNIQUE
REP 1
REP 1`,
`REP 1 IN X
SELECT 1 FROM F AS X
FILTER 'UN-LOCODE' EQ 'RU LED' AS F`,
}
var p PlacementPolicy