From 1f5c22ae3a503bafe6eaa9c0aadfa63ca26872f1 Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Thu, 1 Oct 2020 12:35:29 +0530 Subject: [PATCH 1/2] fix(gqlParser): Handle strings with only whitespace --- gql/parser.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/gql/parser.go b/gql/parser.go index e3788416206..9574886fa82 100644 --- a/gql/parser.go +++ b/gql/parser.go @@ -372,9 +372,6 @@ func substituteVariables(gq *GraphQuery, vmap varMap) error { idVal, ok := gq.Args["id"] if ok && len(gq.UID) == 0 { - if idVal == "" { - return errors.Errorf("Id can't be empty") - } uids, err := parseID(idVal) if err != nil { return err @@ -487,9 +484,6 @@ func substituteVariablesFilter(f *FilterTree, vmap varMap) error { if !ok { return errors.Errorf("Couldn't find value for GraphQL variable: [%s]", v.Value) } - if idVal.Value == "" { - return errors.Errorf("Id can't be empty") - } uids, err := parseID(idVal.Value) if err != nil { return err @@ -2350,8 +2344,11 @@ loop: // Parses ID list. Only used for GraphQL variables. // TODO - Maybe get rid of this by lexing individual IDs. func parseID(val string) ([]uint64, error) { - var uids []uint64 val = x.WhiteSpace.Replace(val) + if val == "" { + return nil, errors.Errorf("ID can't be empty") + } + var uids []uint64 if val[0] != '[' { uid, err := strconv.ParseUint(val, 0, 64) if err != nil { From 17ea052016c6cb40aff778f7be04cb5b9dfe3689 Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Thu, 1 Oct 2020 14:27:21 +0530 Subject: [PATCH 2/2] Add test --- gql/parser_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gql/parser_test.go b/gql/parser_test.go index 3d49bef9959..8384628d9ed 100644 --- a/gql/parser_test.go +++ b/gql/parser_test.go @@ -5443,3 +5443,13 @@ func TestBadCascadeParameterized(t *testing.T) { require.Error(t, err) } } + +func TestEmptyId(t *testing.T) { + q := "query me($a: string) { q(func: uid($a)) { name }}" + r := Request{ + Str: q, + Variables: map[string]string{"$a": " "}, + } + _, err := Parse(r) + require.Error(t, err, "ID cannot be empty") +}