Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/v20.03 - fix(gqlParser): Handle strings with only whitespace in parseID (#6615) #6673

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,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
Expand Down Expand Up @@ -483,9 +480,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
Expand Down Expand Up @@ -2261,8 +2255,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 {
Expand Down
10 changes: 10 additions & 0 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5238,3 +5238,13 @@ func TestFilterWithEmpty(t *testing.T) {
require.NoError(t, err)
require.Equal(t, gq.Query[0].Filter.Func.Args[0].Value, "")
}

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")
}