Skip to content

Handle quotes while building upsert query #9412

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions dgraph/cmd/alpha/upsert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2998,3 +2998,10 @@ func TestLargeStringIndex(t *testing.T) {
require.Contains(t, dqlSchema,
`{"predicate":"name_term","type":"string","index":true,"tokenizer":["term"]}`)
}

func TestStringWithQuote(t *testing.T) {
require.NoError(t, dropAll())
require.NoError(t, alterSchema(`name: string .`))
mu := `{ set { <0x01> <name> "\"problem\" is the quotes (json)" . } }`
require.NoError(t, runMutation(mu))
}
4 changes: 2 additions & 2 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1740,8 +1740,8 @@ func addQueryIfUnique(qctx context.Context, qc *queryContext) error {
// in the mutation, then we reject the mutation.

if !strings.HasPrefix(pred.ObjectId, "val(") {
query := fmt.Sprintf(`%v as var(func: eq(%v,"%v"))`, queryVar, predicateName,
dql.TypeValFrom(pred.ObjectValue).Value)
val := strconv.Quote(dql.TypeValFrom(pred.ObjectValue).Value.(string))
query := fmt.Sprintf(`%v as var(func: eq(%v,"%v"))`, queryVar, predicateName, val[1:len(val)-1])
if _, err := buildQuery.WriteString(query); err != nil {
return errors.Wrapf(err, "error while writing string")
}
Expand Down
Loading