Skip to content

Commit a7483e7

Browse files
authored
Handle quotes while building upsert query (#9412)
Fixes #9405
1 parent 3429849 commit a7483e7

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

.trunk/trunk.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
33
version: 0.1
44
cli:
5-
version: 1.22.15
5+
version: 1.24.0
66

77
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
88
plugins:
99
sources:
1010
- id: trunk
11-
ref: v1.6.8
11+
ref: v1.7.0
1212
uri: https://github.com/trunk-io/plugins
1313

1414
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
1515
runtimes:
1616
enabled:
1717
- go@1.24.3
18-
- node@18.20.5
18+
- node@22.16.0
1919
- python@3.10.8
2020

2121
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
@@ -27,22 +27,22 @@ lint:
2727
- protos/pb/pb.pb.go
2828
enabled:
2929
- golangci-lint2@2.1.6
30-
- trivy@0.62.1
30+
- trivy@0.63.0
3131
- actionlint@1.7.7
32-
- checkov@3.2.421
32+
- checkov@3.2.442
3333
- dotenv-linter@3.3.0
3434
- git-diff-check
3535
- gofmt@1.20.4
3636
- hadolint@2.12.1-beta
37-
- markdownlint@0.44.0
38-
- osv-scanner@2.0.2
37+
- markdownlint@0.45.0
38+
- osv-scanner@2.0.3
3939
- oxipng@9.1.5
4040
- prettier@3.5.3
41-
- renovate@40.0.6
41+
- renovate@40.57.1
4242
- shellcheck@0.10.0
4343
- shfmt@3.6.0
44-
- tflint@0.57.0
45-
- trufflehog@3.88.29
44+
- tflint@0.58.0
45+
- trufflehog@3.89.1
4646
- yamllint@1.37.1
4747
actions:
4848
enabled:

dgraph/cmd/alpha/upsert_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,3 +2998,23 @@ func TestLargeStringIndex(t *testing.T) {
29982998
require.Contains(t, dqlSchema,
29992999
`{"predicate":"name_term","type":"string","index":true,"tokenizer":["term"]}`)
30003000
}
3001+
3002+
func TestStringWithQuote(t *testing.T) {
3003+
require.NoError(t, dropAll())
3004+
require.NoError(t, alterSchemaWithRetry(`name: string @unique @index(exact) .`))
3005+
mu := `{ set { <0x01> <name> "\"problem\" is the quotes (json)" . } }`
3006+
require.NoError(t, runMutation(mu))
3007+
3008+
var data struct {
3009+
Data struct {
3010+
Q []struct {
3011+
Name string `json:"name"`
3012+
} `json:"q"`
3013+
} `json:"data"`
3014+
}
3015+
q := `{ q(func: has(name)) { name } }`
3016+
res, _, err := queryWithTs(queryInp{body: q, typ: "application/dql"})
3017+
require.NoError(t, err)
3018+
require.NoError(t, json.Unmarshal([]byte(res), &data))
3019+
require.Equal(t, `"problem" is the quotes (json)`, data.Data.Q[0].Name)
3020+
}

edgraph/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,8 @@ func addQueryIfUnique(qctx context.Context, qc *queryContext) error {
17461746
// in the mutation, then we reject the mutation.
17471747

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

0 commit comments

Comments
 (0)