surrealdb/surrealdb.go

Bug: query string is butchered when using Go library

Closed this issue · 5 comments

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

  • Run surrealdb in memory surreal start --log trace --user root --pass root memory
  • Create a go file
package main

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?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

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.

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

Thanks for the issue! I've transferred it to the Go library repository. Looks like it may be related to #34 👀

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

surrealdb/surrealdb#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: #62

@ElecTwix thanks, that seems highly likely. Since surrealdb/surrealdb#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.