From 6fe4e2541d0bf1af85ec2666c5502024d14a9237 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 1 Mar 2024 17:30:10 +0300 Subject: [PATCH] [#207] netmap: Fix string escape in PlacementPolicy.String() Signed-off-by: Evgenii Stratonikov --- netmap/policy.go | 10 +++++++--- netmap/policy_decode_test.go | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/netmap/policy.go b/netmap/policy.go index 5d85897..e28c89e 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -940,10 +940,14 @@ func operationFromString(s string) (op netmap.Operation) { return } -// escapeString returns single quote wrapped string if it contains special -// characters '-' and whitespace. +// escapeString returns single quote wrapped string. +// Wrapping rules must be kept in sync with QueryLexer.g4. +// Currently only ASCII letters, digits and underscore can be parsed without quotes. func escapeString(s string) string { - if strings.ContainsAny(s, " -\t") { + for _, r := range s { + if 'a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || '0' <= r && r <= '9' || r == '_' { + continue + } return "'" + s + "'" } return s diff --git a/netmap/policy_decode_test.go b/netmap/policy_decode_test.go index c38b608..0c78fa8 100644 --- a/netmap/policy_decode_test.go +++ b/netmap/policy_decode_test.go @@ -36,6 +36,11 @@ FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, SELECT 1 IN City FROM SPBSSD AS SPB FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS SPBSSD`, + `REP 1 IN FNODE +CBF 1 +SELECT 1 FROM F AS FNODE +FILTER Node EQ '10.78.8.11' AS F`, + `UNIQUE REP 1 REP 1`,