diff --git a/netmap/policy.go b/netmap/policy.go index 28b53900..2884c3fa 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -551,16 +551,17 @@ func writeFilterStringTo(w io.StringWriter, f netmap.Filter) error { // DecodeString decodes PlacementPolicy from the string composed using // WriteStringTo. Returns error if s is malformed. func (p *PlacementPolicy) DecodeString(s string) error { + var v policyVisitor + input := antlr.NewInputStream(s) lexer := parser.NewQueryLexer(input) lexer.RemoveErrorListeners() + lexer.AddErrorListener(&v) stream := antlr.NewCommonTokenStream(lexer, 0) pp := parser.NewQuery(stream) pp.BuildParseTrees = true - var v policyVisitor - pp.RemoveErrorListeners() pp.AddErrorListener(&v) pl := pp.Policy().Accept(&v) diff --git a/netmap/policy_test.go b/netmap/policy_test.go index 0c2782c5..2d04313f 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -25,8 +25,9 @@ SELECT 1 IN City FROM SPBSSD AS SPB FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, } + var p PlacementPolicy + for _, testCase := range testCases { - var p PlacementPolicy require.NoError(t, p.DecodeString(testCase)) @@ -35,6 +36,14 @@ FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, require.Equal(t, testCase, b.String()) } + + invalidTestCases := []string{ + `?REP 1`, + } + + for i := range invalidTestCases { + require.Error(t, p.DecodeString(invalidTestCases[i]), "#%d", i) + } } func TestPlacementPolicyEncoding(t *testing.T) {