Skip to content

Commit

Permalink
correction dgraph-io#9102
Browse files Browse the repository at this point in the history
  • Loading branch information
AoAnima committed Jun 30, 2024
1 parent 3486cf4 commit bdb4f9c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,19 @@ func verifyUnique(qc *queryContext, qr query.Request) error {
return nil
}

// isLatinString checks if the given string contains only Latin letters.
// It iterates over each rune in the string and verifies if it is a letter
// and if it belongs to the Latin script. If any rune does not meet these
// criteria, the function returns false. Otherwise, it returns true.
func isLatinString(s string) bool {
for _, r := range s {
if !unicode.IsLetter(r) || !unicode.Is(unicode.Latin, r) {
return false
}
}
return true
}

// addQueryIfUnique adds dummy queries in the request for checking whether predicate is unique in the db
func addQueryIfUnique(qc *queryContext) error {
if len(qc.gmuList) == 0 {
Expand Down Expand Up @@ -1741,6 +1754,13 @@ func addQueryIfUnique(qc *queryContext) error {
// If the returned UID is different than the UID we have
// in the mutation, then we reject the mutation.

// The following code snippet checks if the variable `predicateName` contains only Latin letters.
// If `predicateName` is not a Latin string, it wraps `predicateName` with angle brackets using
// `fmt.Sprintf`. This is useful for ensuring that non-Latin predicate names are properly formatted
// during the automatic serialization of a structure into JSON.
if !isLatinString(predicateName) {
predicateName = fmt.Sprintf(`<%v>`, predicateName)
}
if !strings.HasPrefix(pred.ObjectId, "val(") {
query := fmt.Sprintf(`%v as var(func: eq(%v,"%v"))`, queryVar, predicateName,
dql.TypeValFrom(pred.ObjectValue).Value)
Expand Down Expand Up @@ -1768,7 +1788,7 @@ func addQueryIfUnique(qc *queryContext) error {
if qc.req.Query == "" {
qc.req.Query = "{" + buildQuery.String()
} else {
qc.req.Query = strings.TrimRight(qc.req.Query, "}")
qc.req.Query = strings.TrimSuffix(qc.req.Query, "}")
qc.req.Query = qc.req.Query + buildQuery.String()
}
}
Expand Down

0 comments on commit bdb4f9c

Please sign in to comment.