Skip to content

Commit

Permalink
Fix caveat string encode to not emit spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Nov 4, 2024
1 parent ac7dfee commit fdceb5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/tuple/core_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tuple

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -118,9 +119,13 @@ func TestCoreRelationToString(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
got, err := CoreRelationToString(tt.input)
require.NoError(t, err)

// Golang randomly injects spaces.
got = strings.ReplaceAll(got, " ", "")
require.Equal(t, tt.expected, got)

got = MustCoreRelationToString(tt.input)
got = strings.ReplaceAll(got, " ", "")
require.Equal(t, tt.expected, got)
})
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/tuple/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sort"
"strings"

"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/structpb"

core "github.com/authzed/spicedb/pkg/proto/core/v1"
Expand Down Expand Up @@ -131,7 +132,10 @@ func StringCaveatContext(context *structpb.Struct) (string, error) {
return "", nil
}

contextBytes, err := context.MarshalJSON()
contextBytes, err := protojson.MarshalOptions{
Multiline: false,
Indent: "",
}.Marshal(context)
if err != nil {
return "", err
}
Expand Down

0 comments on commit fdceb5c

Please sign in to comment.