Skip to content

Commit

Permalink
fix unsupported json encoding with certain characters
Browse files Browse the repository at this point in the history
  • Loading branch information
NoBypass committed Nov 15, 2024
1 parent 89f3b30 commit c229788
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestIntegration(t *testing.T) {

defer db.Close()

a, err := db.Query("RELATE test:123->abc->test:1234", map[string]any{}).First()
t.Logf("result: %v | %v", a, err)

var m []map[string]any
something := db.Scan(&m, "CREATE test:1234 CONTENT $test RETURN AFTER", map[string]any{
"test": map[string]any{
Expand Down
14 changes: 10 additions & 4 deletions rpc/internal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rpc

import (
"bytes"
"context"
"encoding/json"
"github.com/NoBypass/surgo/v2/errs"
Expand Down Expand Up @@ -51,15 +52,20 @@ func (c *WebsocketConn) Send(ctx context.Context, method string, params []any) (
c.mu.Unlock()
}()

reqBytes, err := json.Marshal(&Request{
req := &Request{
ID: id,
Method: method,
Params: params,
})
if err != nil {
}

buf := new(bytes.Buffer)
encoder := json.NewEncoder(buf)
encoder.SetEscapeHTML(false)
if err := encoder.Encode(req); err != nil {
return nil, err
}
err = c.Write(ctx, websocket.MessageText, reqBytes)

err := c.Write(ctx, websocket.MessageText, buf.Bytes())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c229788

Please # to comment.