Fix policy encoding to string #104
2 changed files with 14 additions and 1 deletions
|
@ -471,7 +471,7 @@ func writeFilterStringTo(w io.StringWriter, f netmap.Filter) error {
|
||||||
unspecified := op == 0
|
unspecified := op == 0
|
||||||
|
|
||||||
if s = f.GetKey(); s != "" {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -816,3 +816,12 @@ func operationFromString(s string) (op netmap.Operation) {
|
||||||
|
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,10 @@ FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS
|
||||||
`UNIQUE
|
`UNIQUE
|
||||||
REP 1
|
REP 1
|
||||||
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
|
var p PlacementPolicy
|
||||||
|
|
Loading…
Add table
Reference in a new issue