From 49d03508ed0f1a5f152acf9071f36866bda7e835 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 5 Jul 2023 14:25:24 +0300 Subject: [PATCH 1/2] [#104] netmap: Add test with quote escaping Signed-off-by: Alex Vanin --- netmap/policy_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netmap/policy_test.go b/netmap/policy_test.go index 75167dc..98ce5f2 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -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 -- 2.45.2 From 7ad0ce3c346c74f6c4ceda0fe06d26140c918e71 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 5 Jul 2023 14:25:18 +0300 Subject: [PATCH 2/2] [#104] nemtap: Escape special symbols in filters Signed-off-by: Alex Vanin --- netmap/policy.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/netmap/policy.go b/netmap/policy.go index 06e1cba..323050e 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -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 +} -- 2.45.2