surrealdb / surrealdb.go

SurrealDB SDK for Golang
https://surrealdb.com
Apache License 2.0
231 stars 62 forks source link

Bug: query string is butchered when using Go library #72

Closed Gitopolis closed 1 year ago

Gitopolis commented 1 year ago

Describe the bug

The characters >c in the query for some reason are being replaced with Ϭ, making it impossible for the surrealdb to parse it. The error seems to be consistent, I cannot get rid of it. My code is:

query := "SELECT (SELECT id, name FROM ->own[WHERE time.deleted is NONE]->corporation) AS corporations FROM character:" + req.Msg.CharacterId
log.Printf("query: %s", query)
data, err := db.Query(query, nil)

When Go prints query into the log, it matches the intention, but in the SurrealDB log I see the following:

2023-05-28T03:33:07.540470Z TRACE surrealdb::net: RPC Received: { id: 'mG1GaJASv0zf40jA', method: 'query', params: ['SELECT (SELECT id, name FROM ->own[WHERE time.deleted is NONE]-Ϭorporation) AS corporations FROM character:1d2smxxqd4hexe50zttl', NULL] }

As you can see ->own[WHERE time.deleted is NONE]->corporation has been replaced with ->own[WHERE time.deleted is NONE]-Ϭorporation

Steps to reproduce

import ( "log"

"github.com/surrealdb/surrealdb.go"

)

func main() { db, err := surrealdb.New("ws://localhost:8000/rpc") if err != nil { panic(err) }

if _, err = db.Signin(map[string]interface{}{
    "user": "root",
    "pass": "root",
}); err != nil {
    panic(err)
}

if _, err = db.Use("test", "test"); err != nil {
    panic(err)
}
query := "SELECT ->own[WHERE time.deleted is NONE]->corporation FROM character"
log.Printf("query: %s", query)
_, err = db.Query(query, nil)
if err != nil {
    panic(err)
}

}

* run the file `go run cmd/test/main.go`
* See the output:

2023/05/27 21:00:09 query: SELECT ->own[WHERE time.deleted is NONE]->corporation FROM character panic: sending request failed for method 'query': There was a problem with the database: Parse error on line 1 at character 0 when parsing 'SELECT ->own[WHERE time.deleted is NONE]-Ϭorporation FROM character'

goroutine 1 [running]: main.main() /mnt/c/Users/Nikita/narrow/narrow-services/cmd/test/main.go:29 +0x325 exit status 2



### Expected behaviour

No error

### SurrealDB version

1.0.0-beta.9+20230402.5eafebd for linux on x86_64

### Contact Details

_No response_

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
Gitopolis commented 1 year ago

The code for > is 003E, and code for Ϭ is 03EC, so I guess the c letter in the query somehow being interpreted as a byte.

Gitopolis commented 1 year ago

I just checked with other letters, and all letters from a to f have the same effect. Their combination with > is replaced with corresponding UTF-8 character

finnbear commented 1 year ago

Thanks for the issue! I've transferred it to the Go library repository. Looks like it may be related to https://github.com/surrealdb/surrealdb.go/issues/34 :eyes:

ElecTwix commented 1 year ago

I've transferred it to the Go library repository. Looks like it may be related to #34 eyes

https://github.com/surrealdb/surrealdb/pull/1888 after this I think it needs to be fixed but there is no release probably that's the case

far as I remember it was not related to going to the driver ref: https://github.com/surrealdb/surrealdb.go/issues/62

finnbear commented 1 year ago

@ElecTwix thanks, that seems highly likely. Since https://github.com/surrealdb/surrealdb/pull/1888 indeed fixes wrongly unescaping 5 and 6 hex digits, this issue should not be present in beta 10. I will close this issue, especially since #34 is still open.